MBProgressHUD不会显示

时间:2012-03-24 13:54:29

标签: objective-c ios mbprogresshud

我正在玩MBProgressHUD。 viewcontroller(tableview)中的worflow就是这样:

1)调用IBAction以在两个不同的表之间切换 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不显示?我哪里出错了?

2 个答案:

答案 0 :(得分: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;
祝你好运!

答案 1 :(得分: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];
        });