关于MBP 加载菊花 崩溃到 MBP.m 报: MBProgressHUD needs to be accessed on the main thread.
2017-03-28 10:44
656 查看
MBP的用法:
1、
2、
UI的更新应当总是在主线程上完成的,一些
如果你需要在主线程上执行一个耗时的操作,你需要在执行前稍微延时一下,以使得在阻塞主线程之前,UIKit有足够的时间去更新UI(即绘制HUD).
MBP处理耗时操作的时候要放在主线程中处理,否则会crash。
1、
// 使用MBProgressHUD最重要的准则是当要执行一个耗时任务时,不能放在主线程上影响UI的刷新 // 正确地使用方式是在主线程上创建MBProgressHUD,然后在子线程上执行耗时操作,执行完再在主线程上刷新UI [MBProgressHUD showHUDAddedTo:self.view animated:YES]; dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ // Do something... dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUDForView:self.view animated:YES]; }); });
2、
UI的更新应当总是在主线程上完成的,一些
MBProgressHUD上的属性的setter方法考虑到了线程安全,可以被后台线程安全地调用.这些setter包括setMode:, setCustomView:, setLabelText:, setLabelFont:, setDetailsLabelText:, setDetailsLabelFont: 和 setProgress:.
如果你需要在主线程上执行一个耗时的操作,你需要在执行前稍微延时一下,以使得在阻塞主线程之前,UIKit有足够的时间去更新UI(即绘制HUD).
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; // 如果上面那句话之后就要在主线程执行一个长时间操作,那么要先延时一下让HUD先画好 // 不然在执行任务前没画出来就显示不出来了 dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // Do something... [MBProgressHUD hideHUDForView:self.view animated:YES]; });
MBP处理耗时操作的时候要放在主线程中处理,否则会crash。
相关文章推荐
- MBProgressHUD needs to be accessed on the main thread.报错的解决办法
- MBProgressHUD needs to be accessed on the main thread.
- 日志输出The application may be doing too much work on its main thread.
- 关于谷歌..Synchronous XMLHttpRequest on the main thread is deprecated because of its...
- The application may be doing too much work on its main thread.
- Andriod部分手机频繁闪退,vivo y55a等,Skipped 62 frames! The application may be doing too much work on its main thread
- Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be
- The application may be doing too much work on its main thread.
- The application may be doing too much work on its main thread
- The application may be doing too much work on its main thread.
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th
- The application may be doing too much work on its main thread.
- 自定义view界面提示The application may be doing too much work on its main thread.
- ListView The application may be doing too much work on its main thread
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread
- 蓝牙连接异常,报错The application may be doing too much work on its main thread.
- Choreographer: Skipped 129 frames! The application may be doing too much work on its main thread.
- The application may be doing too much work on its main thread.
- The application may be doing too much work on its main thread.问题可能的解决办法
- Skipped 60 frames! The application may be doing too much work on its main thread