解决这个问题的办法是(两种方法):
1.
[self performSelectorOnMainThread:@selector(reloadUI) withObject:nil waitUntilDone:YES];
reloadUI方法是更新页面的方法
2
dispatch_async(dispatch_get_main_queue(), ^{
[_tableView reloadData];
});
出现这个错的表现:
回调函数里更新页面,更新不了。我今天调了一个网络请求,请求的回调函数里面reload 了tableview,但是发现页面一直没有刷新,还报了这个错,一开始以为是加载太慢,但是用假数据加载很快,后来以为是网络请求数据出来太慢,后来用了
NSDate* start = [NSDate date];
NSLog(@” cost %f ms”, [[NSDate date] timeIntervalSinceDate:start] * 1000);
这个方法来看请求耗时的,后来看见时间也很短,所以我就想到了可能是线程阻塞了,后来看到控制台报了上面那个错误,就去百度了一下,打到了答案。
出现的原因:
当添加了子线程,没有回到主线程中刷新UI 会报错
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.
此应用程序从一个后台线程修改自动布局引擎,这可能导致引擎腐败和奇怪的崩溃。这将导致将来的版本的一个例外。