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.關(guān)于這個問題網(wǎng)上有好多,但是解決辦法好像給的并不明確。告訴我該在回到主線程的時候刷新UI,然而我并不知道這個問題出現(xiàn)的地方在哪里,也不知道哪里需要回到主線程后刷新UI。

  • 首先下載PSPDFUIKitMainThreadGuard(它本身就只有一個.m,你沒有搞錯!)

  • 接著在PSPDFAssertIfNotMainThread方法上打個斷點

60AF00CE-9D7D-4A28-84D2-DDAC5C81CA91.png
  • 報錯后你就可以找到錯誤根源了


    F10B43E3-1631-4FBB-AAD1-776C85F6A1A5.png
  • 最后,就可以把該放進GCD執(zhí)行的代碼放進去就OK了!

dispatch_async(dispatch_get_main_queue(), ^{  
    // Some UIKit call that had timing issues but works fine   
    // in the next runloop.  
    [self updateUI];  
}); 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容