7

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

看起来正在发生的事情是有一个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

后背

4

1 回答 1

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
于 2010-04-05T23:21:49.957 回答