Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C-调用调度\u异步显示错误_Ios_Objective C_Iphone_Xcode - Fatal编程技术网

Ios 目标C-调用调度\u异步显示错误

Ios 目标C-调用调度\u异步显示错误,ios,objective-c,iphone,xcode,Ios,Objective C,Iphone,Xcode,我正在使用dispatch\u 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\u 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.'

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

dispatch_async(dispatch_get_main_queue(), ^{

})

您不应该在后台线程上执行任何与UI相关的代码。