2012-08-31 34 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]; 
     }); 
相关问题