*** Assertion failure in -[MBProgressHUD initWithView:],

* Assertion failure in -[MBProgressHUD initWithView:],
完美解决方式:创建一个类别,将showHUDAddedTo二次封装为showHUDAddedToView,在程序种调用showHUDAddedToView即可,相对原先调用只是多了一个View单词而已,原理是在View为nil时候,加在window上

+(MBProgressHUD *)showHUDAddedToWindowAnimated:(BOOL)animated{

UIWindow * keyWindow = [UIApplication sharedApplication].keyWindow;
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:keyWindow animated:animated];

return hud;

}

+(MBProgressHUD )showHUDAddedToView:(UIView )view animated:(BOOL)animated{

MBProgressHUD *hud = nil;
if (view != nil) {
    hud = [MBProgressHUD showHUDAddedTo:view animated:animated];

}else{
    hud = [MBProgressHUD showHUDAddedToWindowAnimated:animated];

}
return hud;

}

+(void)showToastWithTips:(NSString )tips offset:(CGPoint)offset inView:(UIView )inView{

 MBProgressHUD *hud = [MBProgressHUD showHUDAddedToView:inView animated:YES];
// Set the text mode to show only text.
hud.mode = MBProgressHUDModeText;
hud.label.text = tips;

hud.bezelView.backgroundColor = kC_ThemeCOLOR;

hud.offset = offset;

[hud hideAnimated:YES afterDelay:1.5f];

}

链接:https://share.weiyun.com/4eec5a93fa4985a895404942871a6e21 (密码:y7YICF)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值