UIAlertView 在未记录的方法上崩溃

发布于 2024-08-28 06:47:17 字数 856 浏览 2 评论 0原文

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

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

后背

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七分※倦醒 2024-09-04 06:47:17

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文