2012-08-31 35 views
0

我使用代碼來調用的方法和顯示HUD如下時將顯示對話框,選擇方法無法完成

HUD = [[MBProgressHUD alloc] initWithView:self.view]; 
[self.view addSubview:HUD]; 

HUD.delegate = self; 
HUD.labelText = @"Signing you up"; 

// myProgressTask uses the HUD instance to update progress 
[HUD showWhileExecuting:@selector(processFieldEntries) onTarget:self withObject:nil animated:YES]; 

我有一些錯誤檢查,然後顯示一個對話框processFieldEntries內刪除MBProgressHUD。如下圖所示:

showDialog: 
if (textError) { 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil]; 
    [alertView show]; 
    return; 
} 

然後,這會導致系統崩潰,可能是因爲他們都在同一個線程,沒有從視圖中刪除的HUD。

我的問題是我應該添加不同的代碼以確保它們在不同的線程上運行?我應該添加到processFieldEntries方法,然後刪除HUD,因爲它被稱爲showWhileExecuting ...

回答

2
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    hud.delegate = self; 
    hud.labelText = @"Signing you up"; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.05 * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [self processFieldEntries]; 
     // Do something... 
     [MBProgressHUD hideHUDForView:self.view animated:YES]; 
     }); 
相關問題