首页 > 代码库 > iOS之崩溃处理:This application is modifying the autolayout engine from a background thread
iOS之崩溃处理:This application is modifying the autolayout engine from a background thread
一、错误提示
今天在开发的时候遇到一个崩溃问题,“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,那么只需要在原来的代码里加上这段代码:
iOS之崩溃处理:This application is modifying the autolayout engine from a background thread
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。