1

我想MBProgressHUD在我的 iPhone 应用程序中显示一个而不产生新线程。

我有一组非常复杂的业务逻辑,有时(但不总是)需要等待用户输入,并且在多个线程上运行最终会一次多次要求用户输入,从而导致疯狂的错误。因此,我宁愿避免在主线程之外运行任何东西。但是,由于这个约束,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];

有什么想法吗?

4

2 回答 2

3

这个怎么样?

MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = @"Foo";
// code to execute synchronously
[MBProgressHUD hideHUDForView:self.view animated:YES];
于 2011-12-17T18:12:40.050 回答
1

迟到总比不到好。您可以使用一些运行循环代码来做到这一点。有关详细信息,请参阅此答案

于 2012-04-10T15:53:19.547 回答