iOS 6中的UIAlertView崩溃

Arn*_*yno 5 ios

我有这个代码:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
Run Code Online (Sandbox Code Playgroud)

问题是这个代码在显示警报之前崩溃了,我已经在较低的iOS上测试了它并且它可以工作但是在iOS 6上崩溃了.

Arn*_*yno 10

我找到了答案.我编码:

[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)

代替

[alert show];
Run Code Online (Sandbox Code Playgroud)

它崩溃,因为可能没有在主线程中执行该进程.

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

  • 你的意思是你用[alert performSelectorOnMainThread:@selector(show)withObject:nil waitUntilDone:YES]替换[alert show]; ..... code ... ...对吗? (3认同)