在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不可用,它将永远显示。
我如何通过编程来做到这一点呢?
发布于 2012-01-30 03:28:02
首先执行checkIfApplicationEnabledGPS,当它完成时,你会显示一个警告框,如果你使用UiAlertView来显示警告,那么你可以处理它的委托:-
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
当用户在UiAlert视图中按下ok按钮时,您可以用hudForDownloadData覆盖上面的委托
这样,checkIfApplicationEnabledGPS和hudForDownloadData都将被相继执行
https://stackoverflow.com/questions/9054557
复制相似问题