一次关于更改UI导致autolayout系统崩溃的问题

来源:互联网 发布:小说cms 编辑:程序博客网 时间:2024/05/16 09:20

事情是这样的,我在模型类里写了一个网络请求,在回调里发出个通知,接收通知的页面去对应修改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.

Stack:(

  0   CoreFoundation                      0x000000010fb8bca5 __exceptionPreprocess + 165

  1   libobjc.A.dylib                     0x000000010f604dcd objc_exception_throw + 48

  2   CoreFoundation                      0x000000010fb8bbdd +[NSException raise:format:] + 205

  3   Foundation                          0x000000010f37f7cf _AssertAutolayoutOnMainThreadOnly + 79

  4   Foundation                          0x000000010f1e227e -[NSISEngine withBehaviors:performModifications:] + 31

  5   UIKit                               0x000000011098a304 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 58

  6   UIKit                               0x000000011098ae43 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 249

  7   UIKit                               0x000000011098b90a -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 348

  8   UIKit                               0x00000001101f6b3a -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159

  9   UIKit                               0x00000001102053c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 662

  10  QuartzCore                          0x000000010e85b044 -[CALayer layoutSublayers] + 150

  11  QuartzCore                          0x000000010e84fa44 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366

  12  QuartzCore                          0x000000010e84f8c2 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24

  13  QuartzCore                          0x000000010e84448d _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277

  14  QuartzCore                          0x000000010e8713b8 _ZN2CA11Transaction6commitEv + 508

  15  QuartzCore                          0x000000010e87169a _ZN2CA11Transaction14release_threadEPv + 224

  16  libsystem_pthread.dylib             0x000000011306f72a _pthread_tsd_cleanup + 86

  17  libsystem_pthread.dylib             0x000000011306f451 _pthread_exit + 117

  18  libsystem_pthread.dylib             0x000000011306e6cd _pthread_wqthread + 879

  19  libsystem_pthread.dylib             0x000000011306c40d start_wqthread + 13

)

查阅资料,苹果官方论坛有人这样解释的,说iOS9的API环境下去更新UI对此时执行任务所在的线程要求要高于前几个版本的API,言外之意在不确定此时所在线程是否为主线程时,保险起见,先获取主线程,可以用GCD去获取mainqueue。。。我把更新UI代码放到主线程里就好了。。。希望遇到同样问题的人可以借鉴
0 0
原创粉丝点击