EXC_BAD_ACCESS code 2 on UIAlertView in iOS6

前端 未结 2 929
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 13:43

I\'m trying to figure out why im getting this crash in my app.

It works perfectly fine in Xcode 4.4 running in the simulator with ios5.1, but when i switch into xcod

2条回答
  •  感情败类
    2020-12-13 14:07

    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];
     }
    

提交回复
热议问题