iOS6中UIAlertView上的EXC_BAD_ACCESS代码2

Sea*_*ser 43 exc-bad-access uialertview ios6 xcode4.5

我想弄清楚为什么我在我的应用程序中遇到此崩溃.

它在使用ios5.1的模拟器中运行的Xcode 4.4中运行得非常好,但是当我切换到xcode 4.5和ios6时,我得到一个EXC_BAD_ACCESS代码2.这是我的代码:

- (void) myMethod
{
    UIAlertView *alertview = [[[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil] autorelease];
    alertview.tag = 1
    [alertview show];
}
Run Code Online (Sandbox Code Playgroud)

这是给我一个EXC_BAD_ACCESS码2上[UIAlertView show]线

有任何想法吗?

谢谢!

Eva*_*azo 127

我懂了.我有同样的问题,在我的情况下,似乎该方法现在从后台抛出(现在在ios7中,在ios6中,UIAlertView被自动放入主线程,因为@nodepond说-thanks! - )..

尝试确保从主线程显示该方法:

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

祝好运!

  • 我只是想补充说,当应用程序启动时也会发生此崩溃,如果用户回家并返回,则警报视图显示将导致崩溃.执行performSelectorOnMainThread ...将按照Eva的建议修复它. (3认同)