我在我的应用程序中使用了MBProgressHUD库,但有时甚至进度hud甚至没有显示当我查询大量数据或在数据处理已完成(到那时我不再需要显示hud)。在iOS中使用NSThread和自动释放池的有效方法
在另一篇文章中,我发现有时UI运行周期非常繁忙以至于无法完全刷新,所以我使用了部分解决了问题的解决方案:现在,每个请求都会提升HUD,但几乎有一半次应用程序崩溃。为什么?这是我需要帮助的地方。
我有一个表视图,在委托方法didSelectRowAtIndexPath方法我有这样的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[NSThread detachNewThreadSelector:@selector(showHUD) toTarget:self withObject:nil];
...
}
然后,我有这样的方法:
- (void)showHUD {
@autoreleasepool {
[HUD show:YES];
}
}
在其他一些时候,我只要致电:
[HUD hide:YES];
还有,它工作时它工作,hud显示,保持然后消失,如预期d,有时它只是使应用程序崩溃。错误:EXC_BAD_ACCESS。为什么?
顺便说一句,在HUD对象已经被分配在viewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
...
// Allocating HUD
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Checking";
HUD.detailsLabelText = @"Products";
HUD.dimBackground = YES;
}
你也在做主线程处理吗? – chedabob
是的,我正在快速枚举一些数组,填充一些对象,在集合视图中显示事物......是的,我认为所有这些都是在主线程上完成的...... – Renexandro