gpt4 book ai didi

objective-c - MBProgressHUD 不会显示

转载 作者:行者123 更新时间:2023-11-28 23:01:56 30 4
gpt4 key购买 nike

我正在玩弄 MBProgressHUD。 viewcontroller(tableview)中的工作流程是这样的:

1) IBAction 被调用以在 2 个不同的表之间切换2.1) 函数 reloadAllMonth 被调用(用新表的数据初始化一个数组)2.2) MBProgressHUD *应该显示HUD3)reloadAllMonth完成4) HUD应该消失

我当前的代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

//sparing you the code that determins where the tap occured

HUD = [[MBProgressHUD alloc]initWithFrame:self.view.frame];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self reloadAllMonth];
allMonthIsActive = YES;
[MBProgressHUD hideHUDForView:self.view animated:YES];

// some other code table reload etc.
}

发生了什么:

-> 函数 touchesbegan 被调用-> 3-4 秒内没有任何反应(加载时间)-> 弹出新表

问题:为什么 HUD 不显示?我哪里出错了?

最佳答案

你不能在同一个线程中同时显示和隐藏,这就是我要做的:

-(void)reloadStuff
{
[self reloadAllMonth];
allMonthIsActive = YES;
[MBProgressHUD hideHUDForView:self.view animated:YES];
isLoading = NO;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//sparing you the code that determins where the tap occured

if (isLoading)
return;
isLoading = YES;
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSelectorInBackground:@selector(doStuff) withObject:nil];
}

您也可以删除 ivar HUD,您没有使用它。

并且不要忘记将 viewDidLoad 中的 isLoading 初始化为 NO:

isLoading = NO;

祝你好运!

关于objective-c - MBProgressHUD 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9852288/

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