UIAlertView在未记录的方法上崩溃

Dou*_*ugW 7 iphone crash cocoa-touch uialertview

由于一个难以捉摸的错误,我们的应用程序以大约每1,500个发布一次的频率崩溃.包括堆栈跟踪的相关部分.它被作为回调被解雇,所以我没有参考它在我自己的代码中发生的位置.

看起来正在发生的是有一个UIViewAnimationState对象正在调用UIAlertView'sprivate method(_popoutAnimationDidStop:finished:).唯一的问题是,看来UIAlertView已经被这一点解除了分配.我不会对警报视图做任何奇怪的事情.我把它们扔了,我等待用户输入.它们在被释放之前都被展示出来.

谁遇到过这个?在这一点上,我倾向于它是一个苹果虫.

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
Run Code Online (Sandbox Code Playgroud)

lbacks

cdu*_*uhn 12

UIAlertView可能会在该委托发布后尝试在其委托上调用方法.要防止此类错误,每次将对象设置为另一个对象的委托时,请在委托对象的dealloc方法中将委托属性设置为nil.例如


@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
Run Code Online (Sandbox Code Playgroud)

  • 我面临同样的问题,有人可以指出在AlertView声明为局部变量时如何解决这个问题.我们是否必须在委托回调中将委托设置为nil? (3认同)