无法在iOS中隐藏MBProgressHUD

时间:2013-10-14 04:05:51

标签: ios objective-c mbprogresshud

我尝试使用此代码显示MBProgressHUD,但是当我点击其他标签并返回此标签时,MBProgressHUD无法隐藏。我尝试了两个功能:

updatearray()

 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Loading..";
dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(dispatchQueue, ^(void)
{
[self updatearray];
dispatch_sync(dispatch_get_main_queue(), ^{ 
[hud hide:YES];
});
}); 

用于getVideolist()

 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"Loading..";
    dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(dispatchQueue, ^(void)
    {
    [self getVideolist];
    dispatch_sync(dispatch_get_main_queue(), ^{ 
    [hud hide:YES];
    });
    }); 

第一次,它运行正常。但是在点击另一个选项卡并返回后,它无法隐藏。

1 个答案:

答案 0 :(得分:1)

尝试将MBProgressHUD设为私有财产(强大,非原子)。然后,您可以在其他方法或线程中引用相同的进度hud实例,并更新或隐藏它。