记一个关于线程的错误
上周遇到一个问题,当前页面为一个UIWebView,当点该WebView上某个按钮进入下一个页面时,再通过该页面顶部返回按钮返回时,程序就会崩溃。(在开启了全局断点的情况下)控制台会输出如下提示:
程序崩溃在将要消失时,控制台给出 This application is modifying the autolayout engine from a background thread,whinch can lead to engine corruption and weird crashes.This will cause an exception in a future release. 的报错。
根据提示认为是后台线程在更新UI布局时,webView与JS的交互也在此时进行。交互操作会阻塞UI的显示及刷新。因此,又回到了一个老生常谈的准则上来了, 要在主线程刷新UI布局 。在调用本地应用于H5交互的方法时,要放到主线程中。
#pragma mark - 跳转购物车
- (void)goCart:(NSString *)shopNum
{
CLog(@"jsString = %@",shopNum);
[[NSNotificationCenter defaultCenter] postNotificationName:ShopCartNumIsChanged object:shopNum];
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popToRootViewControllerAnimated:NO];
MallHomeViewController *mallHome = [LYSingle sharedSingle].mallVC;
[mallHome setCurrentSelectIndex:3];
});
}
#pragma mark - 商品上架(未开通店铺不能上架)
- (void)cannotShelves
{
CLog(@"cannotShelves");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"要在主线程刷新UI" delegate:self cancelButtonTitle:@"我知道了" otherButtonTitles:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[alertView show];
});
}
–EOF–
若无特别说明,本站文章均为原创,转载请保留链接,谢谢