2010-07-02 200 views
1

看來,使用MBProgressHUD導致我的應用程序崩潰。如果沒有HUD代碼,以下運行得很好,但有了它,它崩潰:MBProgressHUD導致應用程序崩潰

{ 

    ... 

    HUD = [[MBProgressHUD alloc] initWithView:self.view]; 

    // Add HUD to screen 
    [self.view addSubview:HUD]; 

    // Register for HUD callbacks so we can remove it from the window at the right time 
    HUD.delegate = self; 

    HUD.labelText = @"Connecting"; 

    // Show the HUD while the provided method executes in a new thread 
    [HUD showWhileExecuting:@selector(runLocalNotificationHandler) onTarget:self withObject:nil animated:YES]; 

[[self navigationController] popViewControllerAnimated:YES]; 
} 

- (void) runLocalNotificationHandler 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

[self createLocalNotificationWithBug:[self tempBug]]; 

    [self performSelectorOnMainThread:@selector(finishedUpdatingNotifications) withObject:nil waitUntilDone:NO]; 

    [pool release]; 
} 

- (void)finishedUpdatingNotifications 
{ 

    [[self navigationController] popViewControllerAnimated:YES]; 
} 

- (void)hudWasHidden { 
    // Remove HUD from screen when the HUD was hidden 
    [HUD removeFromSuperview]; 
    [HUD release]; 
} 

以下調試輸出產生:

gdb) continue 
2010-07-02 00:07:55.224 Bugger[16796:207] >>> Entering -[HomeViewController viewDidAppear:] <<< 
2010-07-02 00:07:55.225 Bugger[16796:207] <<< Leaving -[HomeViewController viewDidAppear:] >>> 
2010-07-02 00:07:55.224 Bugger[16796:7007] <<< Leaving -[BugDetailViewController runLocalNotificationHandler] >>> 
2010-07-02 00:07:55.226 Bugger[16796:207] >>> Entering -[BugDetailViewController prepareToolbar] <<< 
2010-07-02 00:07:55.227 Bugger[16796:207] <<< Leaving -[BugDetailViewController prepareToolbar] >>> 
2010-07-02 00:07:55.229 Bugger[16796:207] >>> Entering -[BugDetailViewController dealloc] <<< 
[Switching to process 16796] 
2010-07-02 00:07:55.260 Bugger[16796:207] <<< Leaving -[BugDetailViewController dealloc] >>> 
[Switching to process 16796] 
Program received signal: 「EXC_BAD_ACCESS」. 
(gdb) 

這是怎麼回事?

編輯:回溯:在那個(gdb)提示

Program received signal: 「EXC_BAD_ACCESS」. 
[Switching to process 23788] 
(gdb) bt 
#0 0x029b4a93 in objc_msgSend() 
#1 0x00000000 in ??() 
(gdb) 
+0

當我看到EXC_BAD_ACCESS時,我會將NSZombieEnabled環境變量設置爲YES並進行調試。 – 0x8badf00d 2011-12-27 16:41:00

回答

0

如此接近....

bt<return>和後期回溯。

除此之外,我最好的猜測是您的代表 - 上述代碼中的self - 正在發佈和釋放,沒有首先從MBProgressHUD實例中刪除代理。代表們通常是一個弱引用,因此,這肯定會導致你描述的崩潰。


Ewwww ...你的堆棧已被踩踏!發生這種事時我討厭它。

回到最佳猜測;您的代表是否在作爲MBProgressHUD的代表被刪除之前被釋放? ...你有沒有在你的代碼上運行「構建和分析」?

+0

不,回溯不是很有用: 編程接收信號:「EXC_BAD_ACCESS」。 [切換到進程23788] (gdb)bt #0 0x029b4a93 in objc_msgSend() #1 0x00000000 in ?? () (gdb) – 2010-07-02 13:57:51

+0

「構建和分析」不給我任何有用的文件...所以我不能告訴。據我所知,這個代表並沒有被釋放,但我顯然不能說出來。該代碼並不反映它應該是。 – 2010-07-02 16:57:57

1

我對MBProgress和navigationController的組合有類似的問題,由於某種原因看起來你不能從選擇器調用中調用導航控制器的動作,你只能在主線程中使用導航事件,希望這有助於。