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 中,我进行了一些错误检查,然后显示一个对话框。如下所示:

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

4

1 回答 1

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];
        });
于 2012-09-02T21:09:22.790 回答