iOS 6中的uialertview崩溃



我有此代码:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

问题是该代码在显示警报之前崩溃,我已经在较低的iOS上进行了测试,但在iOS 6上崩溃了。

我找到了答案。我编码:

[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

而不是

[alert show];

它崩溃了,因为该过程可能不会在主线程中执行。

来源来自:https://stackoverflow.com/a/12475858/1179680

最新更新