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(), ^{})方法调起主线程,将代码写在其中

 

posted @ 2021-05-19 17:16  γGama  阅读(4761)  评论(0编辑  收藏  举报