我在和MBProgressHUD玩。视图控制器(tableview)中的worflow是这样的:
1)调用IBAction在两个不同的表之间切换2.1)函数reloadAllMonth被调用(用新表的数据初始化数组) 2.2) MBProgressHUD *HUD应该显示3) reloadAllMonth完成4) reloadAllMonth应该消失
我现在的代码是:
-(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.
}发生了什么:
->函数接触点开始被称为->,在3-4秒(加载时间) ->新表中没有发生任何事情。
问题:为什么没有显示HUD?我哪里出错了?
发布于 2012-03-24 14:34:13
您不能同时在同一个线程中显示和隐藏,这就是我要做的:
-(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];
}此外,您可以移除伊瓦尔HUD,您没有使用它。
并且不要忘记将isLoading在viewDidLoad中初始化为NO:
isLoading = NO;祝好运!
发布于 2015-05-20 14:27:23
你从服务器上拿东西了吗?如果是,请检查您是在传递同步请求还是异步。异步请求是最好的遵循。用这种方式处理MBProgressBar。
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
//Any UI updates should be made here .
[MBProgressHUD hideHUDForView:self.view animated:YES];
});https://stackoverflow.com/questions/9852288
复制相似问题