天天看點

*** 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)

繼續閱讀