MBProgressHUD一个显示消息

时间:2012-01-29 16:05:00

标签: iphone objective-c mbprogresshud

在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不可用,它将永远显示。

我如何以编程方式执行此操作?

1 个答案:

答案 0 :(得分:0)

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

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

当用户在UiAlert视图中按下ok按钮时,您可以使用hudForDownloadData覆盖上面的委托

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