UIAlertView crashing on undocumented method

2019-01-22 16:14发布

Our app has been crashing with a frequency of roughly 1 in 1,500 launches due to a bug that is proving elusive. The relevant portion of the stack trace is included. It's being fired as a callback so I have no reference for where it's occurring in my own code.

It looks like what's going on is there is a UIViewAnimationState object that is calling UIAlertView's private method (_popoutAnimationDidStop:finished:). Only problem is, it appears the UIAlertView has been dealloced by this point. I don't do anything weird with alert views. I throw them up, and I wait for user input. They are all shown before being released.

Anyone encountered this? At this point, I'm leaning toward it being an Apple bug.

Thread 0 Crashed:
0   libobjc.A.dylib                 0x3138cec0 objc_msgSend + 24
1   UIKit                           0x326258c4 -[UIAlertView(Private) _popoutAnimationDidStop:finished:]
2   UIKit                           0x324fad70 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
3   UIKit                           0x324fac08 -[UIViewAnimationState animationDidStop:finished:]
4   QuartzCore                      0x311db05c run_animation_cal

lbacks

1条回答
欢心
2楼-- · 2019-01-22 16:22

It's likely that UIAlertView is trying to call a method on its delegate after that delegate has been released. To prevent this type of bug, any time you set an object as another object's delegate, set the delegate property to nil in the delegate object's dealloc method. e.g.


@implementation YourViewController
@synthesize yourAlertView;

- (void)dealloc {
    yourAlertView.delegate = nil; // Ensures subsequent delegate method calls won't crash
    self.yourAlertView = nil; // Releases if @property (retain)
    [super dealloc];
}

- (IBAction)someAction {
    self.yourAlertView = [[[UIAlertView alloc] initWithTitle:@"Pushed"
                         message:@"You pushed a button"
                         delegate:self
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil] autorelease];
    [self.yourAlertView show];
}

// ...

@end
查看更多
登录 后发表回答