MBProgressHUD导致应用程序崩溃
看来,使用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)
如此接近....
型bt<return>
和后期回溯。
除此之外,我最好的猜测是您的代表 - 上述代码中的self
- 正在发布和释放,没有首先从MBProgressHUD
实例中删除代理。代表们通常是一个弱引用,因此,这肯定会导致你描述的崩溃。
Ewwww ...你的堆栈已被踩踏!发生这种事时我讨厌它。
回到最佳猜测;您的代表是否在作为MBProgressHUD
的代表被删除之前被释放? ...你有没有在你的代码上运行“构建和分析”?
不,回溯不是很有用: 编程接收信号:“EXC_BAD_ACCESS”。 [切换到进程23788] (gdb)bt #0 0x029b4a93 in objc_msgSend() #1 0x00000000 in ?? () (gdb) – 2010-07-02 13:57:51
“构建和分析”不给我任何有用的文件...所以我不能告诉。据我所知,这个代表并没有被释放,但我显然不能说出来。该代码并不反映它应该是。 – 2010-07-02 16:57:57
我对MBProgress和navigationController的组合有类似的问题,由于某种原因看起来你不能从选择器调用中调用导航控制器的动作,你只能在主线程中使用导航事件,希望这有助于。
当我看到EXC_BAD_ACCESS时,我会将NSZombieEnabled环境变量设置为YES并进行调试。 – 0x8badf00d 2011-12-27 16:41:00