主要内容:】
1. 错误提示
2. 错误写法
3. 错误原因
4. 解决问题办法
一、错误提示
今天在开发的时候遇到一个崩溃问题,“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.”如图所示:

二、错误写法
先来看一下代码的写法,如图所示:

三、错误原因
后来观察代码后发现居然是在子线程里更新了UI导致的崩溃。在我们学习多线程的时候肯定会看到一句话:UI一定要在主线程中更新。这就是导致崩溃的主要原因,写代码GCD相关的代码一定切记更新UI的操作一定要放在主线程操作。
四、解决问题办法
既然知道了要在主线程更新UI,那么只需要在原来的代码里加上这段代码:
[objc] view plain copy print?在CODE上查看代码片派生到我的代码片
dispatch_async(dispatch_get_main_queue(), ^{
//inset code....
});
如图:

网友评论