首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MBProgressHUD不会显示

MBProgressHUD不会显示
EN

Stack Overflow用户
提问于 2012-03-24 13:54:28
回答 2查看 1.3K关注 0票数 0

我在和MBProgressHUD玩。视图控制器(tableview)中的worflow是这样的:

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

我现在的代码是:

代码语言:javascript
复制
-(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?我哪里出错了?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-24 14:34:13

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

代码语言:javascript
复制
-(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:

代码语言:javascript
复制
isLoading = NO;

祝好运!

票数 2
EN

Stack Overflow用户

发布于 2015-05-20 14:27:23

你从服务器上拿东西了吗?如果是,请检查您是在传递同步请求还是异步。异步请求是最好的遵循。用这种方式处理MBProgressBar。

代码语言:javascript
复制
  [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];
        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9852288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档