2012-03-29 58 views
-1

我在iPhone和内部使用的块,我只是显示一个标题和文字UIAlertView
问题是警报视图有时会出现很长时间。 在其他地区的工作正常。 任何人都可以建议我可能是什么原因?UIAlertView在一段时间后来临

+1

后一些代码。 – Hiren 2012-03-29 05:40:06

+0

它在哪里运行......你需要发布一些代码。 – Jamie 2012-03-29 05:42:46

回答

3

必须从主线程处理UI *元素。如果您使用块在后台运行某些内容,则会在主线程的dispatch_queue中包装所有对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]; 
    }); 
}); 
+2

或者,'[self performSelectorOnMainThread:@selector(MethodThatShowsAlert :) withObject:IfAnything waitUntilDone:NO];' – tipycalFlow 2012-03-29 06:09:37

+0

非常感谢。有效。 – iVipS 2012-03-29 06:28:31