5

我有这个代码:

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

问题是这段代码在显示警报之前就崩溃了,我已经在较低的 iOS 上对其进行了测试,它可以工作,但在 iOS 6 上它会崩溃。

4

1 回答 1

10

我找到了答案。我编码:

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

代替

[alert show];

它崩溃是因为该进程可能不在主线程中执行。

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

于 2012-10-18T09:29:24.140 回答