2013-04-04 212 views
0

這裏是我的代碼MBProgressHUD沒有停止

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
hud.mode = MBProgressHUDModeIndeterminate; 
hud.labelText = @"Loading.."; 
dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 
dispatch_async(dispatchQueue, ^(void) 
{ 
    [self information]; 
    [hud hide:YES]; 
}); 

我知道一段時間後,該方法的信息完成。但即使完成後,進度條也不會移開。可能是什麼原因?

+0

嘗試調用'[HUD隱藏:YES];'使用'performSelectorOnMainThread主線:withObject:'方法 – 2013-04-04 12:43:04

+0

你能詳細闡述一下嗎?我是一個新手。 – 2013-04-04 12:49:31

+1

所以你現在得到正確的答案嘗試使用那一個它是完全正確的你:) – 2013-04-04 12:54:58

回答

3

做這樣的

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
hud.mode = MBProgressHUDModeIndeterminate; 
hud.labelText = @"Loading.."; 
dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 
dispatch_async(dispatchQueue, ^(void) 
{ 
[self information]; 
dispatch_sync(dispatch_get_main_queue(), ^{ 
[hud hide:YES]; 
}); 
}); 
+1

工程出來好!你能解釋我在那裏究竟做了什麼? – 2013-04-04 12:58:46

+3

您在dispatch_async中隱藏HUD,並且我的朋友不是主線程。您可以使用dispath_sync或performSelectorOnMainThread。記住任何UI更新都應該在主線程和主線程中完成。 – satheeshwaran 2013-04-04 13:01:38

+0

非常感謝! – 2013-04-04 13:04:33