0

在 viewDidload 方法中,我MBProgressHUD用于显示活动指示器,直到从网络下载数据,然后检查应用程序是否启用了 GPS。基于此,我提醒用户使用MBProgressHUD.

我的代码;

ViewDidLoad

hudForDownloadData = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view hudForDownloadData ];   
hudForDownloadData .delegate = self;
hudForDownloadData .labelText = @"Loading";
hudForDownloadData .detailsLabelText = @"updating data";
[hudForDownloadData showWhileExecuting:@selector(downloadDataFromWebService) onTarget:self withObject:nil animated:YES];

[self downloadDataFromWebService]; // This method is called, and then data is downloaded from the webservice, once the data is downloaded i will remove the `MBProgressHUD ` alert

现在我正在检查应用程序是否启用了对 GPS 的访问,如果没有则提醒用户。

 hudForGPS = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
     [self.navigationController.view addSubview:HUD];   
     hudForGPS .delegate = self;
     hudForGPS .labelText = @"Loading";
     hudForGPS .detailsLabelText = @"updating data";
     [hudForGPS showWhileExecuting:@selector(checkIfApplicationEnabledGPS)
onTarget:self withObject:nil animated:YES]; // This will only take a
 maximum of 2-3 seconds. and i will remove it after that

问题是;当互联网/wifi 关闭时,hudForDownloadData将持续动画(显示 uiactivityindicator)。同时hudForGPS也会执行。但它会显示在下面hudForDownloadData。所以用户将无法看到它。

我想要做的是执行第checkIfApplicationEnabledGPS一个,并等到它的警报完成(它只需要 2-3 秒),然后加载执行downloadDataFromWebService如果互联网/wifi 不可用,它将永远显示。

我怎样才能以编程方式做到这一点?

4

1 回答 1

0

首先执行 checkIfApplicationEnabledGPS 完成后,您会显示一个警报框,如果您使用 UiAlertView 显示警报,那么您可以处理它的委托:-

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

当用户在 UiAlert 视图中按下确定按钮时,您可以使用 hudForDownloadData 覆盖上述委托

这样,checkIfApplicationEnabledGPS 和 hudForDownloadData 都会一个接一个地执行

于 2012-01-29T19:28:02.173 回答