设置MBProgressHUD的超时

时间:2013-12-30 19:17:55

标签: ios objective-c mbprogresshud

我正在使用MBProgressHUD在下载Web服务数据时显示活动指示器。该应用程序通常用于连接性较差的农村地区,因此我希望能够将HUD的超时设置为10秒(仅为任意数字)。我不知道该如何解决这个问题。有人可以提供建议吗?谢谢!

MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];

NSString *info = [NSString stringWithFormat:@"Loading %@ gauges", self.stateIdentifier];
[hud setLabelText:info];
[hud setDetailsLabelText:@"Please wait..."];
[hud setDimBackground:YES];
[hud setOpacity:0.5f];
[hud show:YES];

[self.view addSubview:hud];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    stateGauges = [[GaugeList alloc] initWithStateIdentifier:stateIdentifier andType:nil];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
        [hud removeFromSuperview];
    });
});

2 个答案:

答案 0 :(得分:11)

您可以使用:

- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay;

MBProgressHUD的方法。

创建MBProgressHUD,如:

MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:hud];
NSString *info = [NSString stringWithFormat:@"Loading %@ gauges", self.stateIdentifier];
[hud setLabelText:info];
[hud setDetailsLabelText:@"Please wait..."];
[hud setDimBackground:YES];
[hud setOpacity:0.5f];
[hud show:YES];
[hud hide:YES afterDelay:10.0];

答案 1 :(得分:1)

对于Swift,以下是解决方案:

let progressHUD = MBProgressHUD.showHUDAddedTo(self.view, animated: true)

progressHUD.hideAnimated(true, afterDelay: 5)