在 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 不可用,它将永远显示。
我怎样才能以编程方式做到这一点?