我正在使用代码来调用方法并显示如下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中,我进行了一些错误检查,然后显示了一个对话框。如下所示:

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...。

最佳答案

    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];
        });

关于objective-c - 显示对话框且选择器方法未完成时,删除MBProgressHUD,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12213508/

10-12 16:08