[英]Strange UIAlertView private method crash _performPopup
我試圖找出由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
聽起來像委托在這里引起問題。 對於不需要跟蹤用戶輸入的簡單UIAlertView,可以將委托設置為nil,例如:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Alert" message: @"My Message" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
如果確實需要委托方法,只需確保在丟失視圖時將UIAlertView的委托設置為零即可:
alert.delegate = nil;
在dealloc或viewWillDisappear中:取決於代碼的設置方式!
當應用程序進入后台時,關閉並取消警報視圖也是一個好主意。
將以下內容添加到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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.