0

我正在玩 MBProgressHUD。视图控制器(tableview)中的工作流程是这样的:

1) 调用 IBAction 以在 2 个不同的表之间切换 2.1) 调用函数reloadAllMonth(使用新表的数据初始化数组) 2.2) MBProgressHUD *HUD 应该显示 3) 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不显示?我哪里做错了 ?

4

2 回答 2

2

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

-(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;

祝你好运!

于 2012-03-24T14:34:13.297 回答
0

你在从服务器获取任何东西吗?如果是这样,请检查您是在传递同步请求还是异步请求。最好遵循异步请求。以这种方式处理 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];
        });
于 2015-05-20T14:27:23.963 回答