OGeek|极客世界-中国程序员成长平台

标题: ios - Objective C - 调用 dispatch_async 显示错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:32
标题: ios - Objective C - 调用 dispatch_async 显示错误

我正在使用 dispatch_async 在其他方面做一些事情。

dispatch_queue_t backgroundQueue;

在viewDidLoad中:

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view.

   backgroundQueue = dispatch_queue_create("dispatchName", NULL);
}

使用它:

dispatch_async(backgroundQueue, ^
{
    // Do something...
});

在我再次调用此方法之前一切正常。 该应用程序因错误而崩溃:

2014-09-29 11:34:10.626 hELLO[2785:389790] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3318/Keyboard/UIKeyboardTaskQueue.m:374
2014-09-29 11:34:10.628 hELLO[2785:389790] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'



Best Answer-推荐答案


您正在尝试执行进程,该进程只能在主线程中执行。 将代码放入

dispatch_async(dispatch_get_main_queue(), ^{

})

关于ios - Objective C - 调用 dispatch_async 显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26095672/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4