gpt4 book ai didi

ios - 当 JSON 调用时间过长时允许用户取消 MBProgressHUD

转载 作者:可可西里 更新时间:2023-11-01 03:35:28 31 4
gpt4 key购买 nike

我已经阅读和阅读了关于此的内容,但我似乎找不到任何符合我情况的内容。

当 View 出现时,我已经加载了 MBProgressHUD,因为我的应用程序会立即获取一些网络服务数据。我的问题是我的导航 Controller 上的后退按钮在显示 HUD 时没有响应(因此在应用程序获取其数据时)。我希望用户能够点击关闭(或者在最坏的情况下能够点击后退按钮)以摆脱困境,如果这是无休止的等待。这是我在 View 出现后立即运行的代码:

#ifdef __BLOCKS__
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.labelText = @"Loading";
hud.dimBackground = NO;
hud.userInteractionEnabled = YES;

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Do a task in the background
NSString *strURL = @"http://WEBSERVICE_URL_HERE";

//All the usual stuff to get the data from the service in here

NSDictionary* responseDict = [json objectForKey:@"data"]; // Get the dictionary
NSArray* resultsArray = [responseDict objectForKey:@"key"];


// Hide the HUD in the main tread
dispatch_async(dispatch_get_main_queue(), ^{

for (NSDictionary* internalDict in resultsArray)
{
for (NSString *key in [internalDict allKeys])
{//Parse everything and display the results
}

}

[MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
});
});
#endif

抛开所有关于解析 JSON 的乱码。这一切工作正常,HUD 在数据出现并显示后消失。我究竟该如何启用一种方法来停止所有这一切并返回到(空白)界面?手势识别器?我会在 MBProgressHUD 类中设置它吗?好郁闷……

非常感谢您的帮助。很抱歉发了这么长的帖子。对于我丑陋的代码...

最佳答案

无需扩展 MBProgressHUD。只需向其中添加一个 UITapGestureRecognizer

ViewDidLoad:

MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:NO];
HUD.mode = MBProgressHUDModeAnnularDeterminate;

UITapGestureRecognizer *HUDSingleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
[HUD addGestureRecognizer:HUDSingleTap];

然后:

-(void)singleTap:(UITapGestureRecognizer*)sender
{
//do what you need.
}

关于ios - 当 JSON 调用时间过长时允许用户取消 MBProgressHUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13212467/

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