我正在使用代码来调用方法并将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 ...
答案 0 :(得分: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];
});