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方法上打个断点

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._第1张图片
60AF00CE-9D7D-4A28-84D2-DDAC5C81CA91.png
  • 报错后你就可以找到错误根源了


    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._第2张图片
    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];  
}); 

你可能感兴趣的:(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.)