gpt4 book ai didi

ios - 为 MBProgressHUD 设置超时

转载 作者:可可西里 更新时间:2023-11-01 05:03:56 24 4
gpt4 key购买 nike

我正在使用 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];
});
});

最佳答案

您可以使用:

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

关于ios - 为 MBProgressHUD 设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20845966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com