【发布时间】:2013-10-08 20:41:44
【问题描述】:
我在我的应用程序中使用 MBProgressHUD 库,但有时当我查询大量数据时进度 hud 甚至不显示,或者在数据处理完成后立即显示(到那时我不再需要显示 hud)。
在另一篇文章中,我发现有时 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];
好吧,当它工作时,它会按预期显示、停留然后消失,有时它只会让应用程序崩溃。错误: 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;
}
【问题讨论】:
-
你也在主线程上做处理吗?
-
是的,我正在快速枚举一些数组,填充一些对象,在集合视图中显示东西......是的,我认为所有这些都是在主线程上完成的......跨度>
标签: ios uitableview nsthread nsautoreleasepool mbprogresshud