我想在我的iPhone应用程序中显示一个MBProgressHUD
而不产生新线程。
我有一组非常复杂的业务逻辑,有时(但并非总是)需要等待用户输入,并且在多个线程上运行最终会一次要求多次用户输入,从而导致疯狂的错误。因此,我宁愿避免在主线程上运行任何东西。但是,由于这个限制,由于主线程被阻塞,因此MBProgressHUD
没有显示!通常,我将使用以下代码创建MBProgressHUD
:
[HUD showWhileExecuting:@selector(myWorkerMethod) onTarget:self withObject:nil animated:YES];
但是我想使用以下代码而不阻塞主线程:
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.minShowTime = 0.0;
HUD.labelText = @"some text";
[HUD show:YES];
有什么想法吗?
最佳答案
这个怎么样?
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = @"Foo";
// code to execute synchronously
[MBProgressHUD hideHUDForView:self.view animated:YES];
关于iphone - 如何在不产生新线程的情况下在iPhone上显示MBProgressHUD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585389/