2012-01-29 21 views
0

在viewDidload方法中,我使用MBProgressHUD來顯示一個活動指示器,直到從網上下載數據,然後檢查應用程序是否已啓用GPS。基於此,我提醒用戶使用MBProgressHUDMBProgressHUD顯示消息一個在另一個上

我的代碼;

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 

問題是:當互聯網/無線網絡關閉時,hudForDownloadData將持續動畫(顯示uiactivityindicator)。同時hudForGPS也會執行。但它將顯示在hudForDownloadData以下。所以用戶將無法看到它。

我想要做的是首先執行checkIfApplicationEnabledGPS,然後等到其警報結束(僅需要2-3秒),然後加載執行downloadDataFromWebService,如果internet/wifi不可用,它將會永遠顯示。

如何以編程方式執行此操作?

回答

0

執行checkIfApplicationEnabledGPS第一,當它結束時,你顯示一個警告框,如果你正在使用UIAlertView中,以示警戒,那麼你可以處理它的委託 -

- (空)alertView:(UIAlertView中*) alertView clickedButtonAtIndex:(NSInteger的)buttonIndex當用戶在按下UiAlert OK按鈕

視圖中,可以用hudForDownloadData

覆蓋上面代表以這種方式兩個checkIfApplicationEnabledGPS和hudForDownloadData將其他

後執行的一個
+0

我需要在這兩種情況下使用自定義警報(MBProgressHUD) – Illep 2012-01-30 00:36:30

+0

在這種情況下也不會有問題,您可以創建自己的alertview並可以處理自己的按鈕的IBactions – 2012-01-30 05:07:13

+0

hudWasHidden,是否使用此代理的MBProgressHUD checkIfApplicationEnabledGPS完成了嗎? – 2012-01-30 05:11:52