简体   繁体   English

UIAlertView过了一段时间

[英]UIAlertView comes after some time

I am using blocks in iPhone and inside that I am just showing an UIAlertView with a title and text. 我在iPhone中使用块,并且在其中仅显示带有标题和文本的UIAlertView
The problem is that the alert view sometimes has very long to appear. 问题是警报视图有时显示很长时间。 On other areas its working fine. 在其他方面,它的工作很好。 Can anyone suggest me what may be the reason? 谁能建议我可能是什么原因?

UI* elements must be handled from the main thread. UI *元素必须从主线程处理。 If you use a block to run something in the background wrap all calls to UI* in the dispatch_queue of the main thread. 如果使用块在后台运行某些内容,则将对UI*所有调用包装在主线程的dispatch_queue中。

like this: 像这样:

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];
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM