Mac開發——報錯:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'


完整報錯

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!' terminating with uncaught exception of type NSException

原因

所有AppKit / GUI調用都需要在主線程中進行,無法在其他線程執行。

解決辦法

在主線程執行代碼,如果該代碼在其他子線程當中,則可以用dispatch_async(dispatch_get_main_queue(), ^{})方法調起主線程,將代碼寫在其中

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM