iOS This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.


This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.关于这个问题网上有好多,但是解决办法好像给的并不明确。告诉我该在回到主线程的时候刷新UI,然而我并不知道这个问题出现的地方在哪里,也不知道哪里需要回到主线程后刷新UI。

  • 首先下载PSPDFUIKitMainThreadGuard(它本身就只有一个.m,你没有搞错!)

  • 接着在PSPDFAssertIfNotMainThread方法上打个断点

60AF00CE-9D7D-4A28-84D2-DDAC5C81CA91.png
  • 报错后你就可以找到错误根源了


    F10B43E3-1631-4FBB-AAD1-776C85F6A1A5.png
  • 最后,就可以把该放进GCD执行的代码放进去就OK了!

dispatch_async(dispatch_get_main_queue(), ^{  
    // Some UIKit call that had timing issues but works fine   
    // in the next runloop.  
    [self updateUI];  
}); 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容