Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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
Iphone UIAlertView会在一段时间后出现_Iphone_Ios_Xcode - Fatal编程技术网

Iphone UIAlertView会在一段时间后出现

Iphone UIAlertView会在一段时间后出现,iphone,ios,xcode,Iphone,Ios,Xcode,我在iPhone中使用了块,我只是显示了一个带有标题和文本的UIAlertView。 问题是,警报视图有时需要很长时间才能出现。 在其他方面,其工作良好。 有人能告诉我原因是什么吗?UI*元素必须从主线程处理。如果使用块在后台运行某些内容,请将所有调用包装到主线程的分派队列中的UI* 像这样: dispatch_async(myQueue, ^{ // do something in background dispatch_async(dispatch_get_main_queu

我在iPhone中使用了块,我只是显示了一个带有标题和文本的
UIAlertView

问题是,警报视图有时需要很长时间才能出现。 在其他方面,其工作良好。
有人能告诉我原因是什么吗?

UI*元素必须从主线程处理。如果使用块在后台运行某些内容,请将所有调用包装到主线程的分派队列中的
UI*

像这样:

dispatch_async(myQueue, ^{
    // do something in background
    dispatch_async(dispatch_get_main_queue(), ^{
        // Interaction with User Interface Elements on the main thread...
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Foo" message:@"Bar" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [alert show];
    });
});

它运行在哪个块中…您需要发布一些代码。或者,
[self-performSelectorOnMainThread:@selector(MethodThatShowsAlert:)with object:IfAnything waitUntilDone:NO]