UIAlertView在未记录的方法上崩溃

时间:2010-04-05 20:48:48

标签: iphone cocoa-touch crash uialertview

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

看起来正在发生的是UIViewAnimationState对象正在调用UIAlertView's私有方法(_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

lbacks

1 个答案:

答案 0 :(得分:12)

UIAlertView可能会在该委托发布后尝试在其委托上调用方法。要防止此类错误,每次将对象设置为另一个对象的委托时,请在委托对象的dealloc方法中将委托属性设置为nil。 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
相关问题