2013-12-23 23 views
0

我正在使用ASIHTTP類與服務器進行通信。現在,當任何請求完成時,它顯示進程欄,直到請求沒有服務器沒有響應或超時。現在,我想要在警報視圖中單擊yes按鈕時發出請求。當我在做這個進程欄時只是顯示一段時間。直到請求完成時才顯示。ASIHTTP類進程條

- (IBAction)sendGratuity:(id)sender { 

if([[txtAmount.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]>0){ 
    UIAlertView *confirmAlert = [[UIAlertView alloc] initWithTitle:@"Confirm" 
                message:@"Are you really want to send gratuity to this User?" 
                delegate:self 
              cancelButtonTitle:@"No" 
              otherButtonTitles:@"Yes", nil]; 
    [confirmAlert show]; 

} 
else{ 
    [self sendGratuityRequest]; //if request made from here then it is working fine 
} 

AlertView方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
if(buttonIndex==1){ 
    [self sendGratuityRequest]; 
} 

} 

回答

0

進度條是否添加到頂層UIWindow?

我的猜測是,因爲UIAlertView創建了自己的UIWindow,所以sendGratuityRequest中的代碼將欄添加到該窗口中,該按鈕將在按下按鈕後立即刪除。

兩個可能的解決方案:

  1. 把你的代碼alertView:didDismissWithButtonIndex:,而不是alertView: clickedButtonAtIndex:。 (我不是100%確定這會修復它。)

  2. 使用更好的邏輯來選擇正確的UIWindow。正確的代碼可能是這樣的,但是你的應用程序如何使用UIWindows可以根據不同的:

    NSEnumerator *frontToBackWindows = [[[UIApplication sharedApplication]windows]reverseObjectEnumerator]; 
    
    for (UIWindow *window in frontToBackWindows) 
        if (window.windowLevel == UIWindowLevelNormal) { 
         // Add the progress bar to this UIWindow 
         break; 
        } 
    
0

可能是你改變networkActivityIndicatorVisible標誌的價值別處。在您的代碼中搜索[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

+0

我覺得OP是詢問一個進度條,而不是網絡活動指示燈。 –

+0

@AaronBrager可能是它的網絡活動指示器,因爲它在我提出請求時顯示(顯示進程正在進行的循環)...而且我也認爲你是正確的......它可能在警報視圖窗口中....我會嘗試你的建議,然後讓你知道 – vivek