MBProgressHUD导致应用程序崩溃

时间:2010-07-02 04:24:39

标签: iphone objective-c ipad

似乎使用MBProgressHUD导致我的应用程序崩溃。如果没有HUD代码,以下运行正常,但有了它,它崩溃了:

{

    ...

    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) 

这里发生了什么?

编辑:Backtrace:

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

2 个答案:

答案 0 :(得分:1)

我对这个MBProgress和navigationController的组合有类似的问题,由于某种原因看起来你不能从选择器调用中调用导航控制器动作,你必须只在主线程中使用导航事件,希望这有帮助。

答案 1 :(得分:0)

如此接近......

bt<return>提示符下输入(gdb)并发布回溯。

除此之外,我最好的猜测是你的代理 - 上面代码中的self正在被释放和解除分配,而不是先从MBProgressHUD实例中删除代理。代表通常是一个弱引用,因此,这肯定会导致您描述的崩溃。


Ewwww ......你的筹码被踩了!发生这种情况时我讨厌它。

回到最好的猜测;您的代理是否在被MBProgressHUD作为代理人删除之前被解除分配? ...你在代码上运行“构建和分析”吗?