8

我试图找出由 UIAlertView 中的私有方法引起的崩溃。我的应用程序崩溃中大约有一半涉及此问题。

-[UIAlertView(Private) _performPopup:animationType:revealedBySpringBoardAlert:]

这是我的崩溃报告中的部分。困扰我的是,我的大多数警报视图都是由旨在存在于整个应用程序生命周期中的单例对象弹出的。所以我不确定这是否是由于 UIAlertView 的委托在被它调用之前被释放造成的。有没有人见过这个?你能给些建议么?谢谢。

Hardware Model:      iPhone4,1
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2012-11-15 11:31:57.452 -0800
OS Version:      iOS 6.0.1 (10A523)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x5354440a
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x33ab95b6 objc_msgSend + 22
1   UIKit                           0x32e52fa0 -[UIAlertView(Private) _performPopup:animationType:revealedBySpringBoardAlert:]
2   UIKit                           0x330621c4 -[UIAlertView(Private) _repopupNoAnimation]
3   UIKit                           0x33065b38 __36-[_UIAlertStackWatcher _appResumed:]_block_invoke_0
4   libdispatch.dylib               0x37ec211c _dispatch_call_block_and_release
5   libdispatch.dylib               0x37ec14b4 _dispatch_client_callout
6   libdispatch.dylib               0x37ec61b8 _dispatch_main_queue_callback_4CF$VARIANT$mp
7   CoreFoundation                  0x39ba2f36 __CFRunLoopRun
8   CoreFoundation                  0x39b15eb8 CFRunLoopRunSpecific
9   CoreFoundation                  0x39b15d44 CFRunLoopRunInMode
10  GraphicsServices                0x37ee32e6 GSEventRunModal
11  UIKit                           0x32d552f4 UIApplicationMain
12  MYAPP                           0x0000334a main + 70
13  MYAPP                           0x000032fc start + 36
4

2 回答 2

3

听起来代表在这里造成了问题。对于不需要跟踪用户输入的简单 UIAlertViews,您可以将委托设置为 nil,例如:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Alert" message: @"My Message" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

如果您确实需要委托方法,只需确保在丢失视图时将 UIAlertView 的委托设为 nil:

alert.delegate = nil;

在 dealloc 或 viewWillDisappear 中:取决于您的代码是如何设置的!

于 2012-12-20T21:28:25.473 回答
0

当应用程序进入后台时,关闭并取消警报视图也是一个好主意。

将以下内容添加到 viewDidLoad 方法中:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];

然后,handleApplicationDidEnterBackground 的实现应该如下所示:

- (void)handleApplicationDidEnterBackground:(NSNotification *)n
{
    if (self.alertView)
    {
        self.alertView.delegate = nil;
        [self.alertView dismissWithClickedButtonIndex:[self.alertView cancelButtonIndex] animated:NO];
        self.alertView = nil;
    }
}
于 2013-08-13T20:14:47.513 回答