UIAlertView in ARC application

I have a one-button iphone app. When pressed, it calls the code:

UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"test"
                          message:@"test"
                          delegate:self
                          cancelButtonTitle:@"Ok"
                          otherButtonTitles: nil];
[alert show];

The application supports ARC.

The problem is that if I click the "OK" button in the warning, the application crashes with EXC_BAD_ADDRESS - perhaps due to the warning it is already deleted by the arc.

What is recommended to solve this problem? without adding viewcontroller property

thank

+3
source share
2 answers

My assumption is that you did not implement the UIAlertViewDelegate methods or that you yourself have gone out of scope.

If you do not care about being alerted when someone rejects the alert window, change the delegate to zero. eg.

UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"test"
                          message:@"test"
                          delegate:nil
                          cancelButtonTitle:@"Ok"
                          otherButtonTitles: nil];
[alert show];
+5

UIAlertView ( assign). , ARC , ( ). UIAlertView.

@property(nonatomic,assign) id /*<UIAlertViewDelegate>*/ delegate;    // weak reference

, , , UIAlertView, , .

, , , , ​​ . , , , UIAlertView. , .

assign. iPhone ARC - dealloc ?

+5

All Articles