我在我的應用程序中使用了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