EXC_BAD_ACCESS code 2 on UIAlertView in iOS6

半城伤御伤魂 提交于 2019-11-28 18:09:42

I've got it. I have the same problem, in my case it seems that the method is thrown from background now (now in ios7, in ios6 UIAlertView was automatically put into the main-thread as @nodepond says -thanks!-)..

try to assure that the method is shown from main thread:

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

Good luck!

It's happened with me, even in 2014. The problem is want to use an object already released.

What I did wrong:

//class B with UIAletViewDelegate

-(void) showAlert{
 UIAlertView * alert = [[UIAlertView alloc] initWithTitle bla bla...];
 [alert show];
}


//class A
viewDidLoad{
 MyClassB *B = [[B alloc] init];
 [B showAlert];
}

What is the right way:

//Class A
@implementation A{
    ClassB *B;
}

 viewDidLoad{
     B = [[B alloc] init];
     [B showAlert];
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!