gpt4 book ai didi

iphone - 如何在不产生新线程的情况下在iPhone上显示MBProgressHUD?

转载 作者:行者123 更新时间:2023-12-01 18:32:13 25 4
gpt4 key购买 nike

我想在我的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com