2013-04-21 99 views
0

我有一個登錄視圖,用戶將用於登錄到我的應用程序。 我使用NSURLConnection Asynchrounous請求塊連接到我的Web服務並來回傳遞數據。iOS - NSURLConnection異步請求一次,然後失敗(掛起)第二次嘗試

我有一個奇怪的問題,如果用戶第一次登錄,它工作正常。但是,如果他們註銷,然後嘗試再次登錄請求發送,但從來沒有響應(我設置所有場景的alertviews;即超時,數據=無,錯誤!=零等)。它只是與我顯示的加載屏幕坐在那裏,並從不做任何事情。

我是否錯過了什麼?

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
    { 
     if ([data length] > 0 && error == nil){ 
      if(data != nil) { 
        //Handle Data Here 
        .............  
      } else { 
       [loadingView removeFromSuperview]; 
       loadingView = nil; 
       BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"Network connection was successful, but there was a problem with data transfer.\nPlease try again."]; 
       [alert setCancelButtonWithTitle:@"OK" block:nil]; 
       [alert show];    } 
     } 
     else if ([data length] == 0 && error == nil){ 
      [loadingView removeFromSuperview]; 
      loadingView = nil; 
      BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"Network connection was successful, but there was a problem with data transfer.\nPlease try again."]; 
      [alert setCancelButtonWithTitle:@"OK" block:nil]; 
      [alert show]; 
     } 
     else if (error != nil && error.code == NSURLErrorTimedOut){ 
      [loadingView removeFromSuperview]; 
      loadingView = nil; 
      BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"The network request timed out.\nPlease check your internet connection and try again."]; 
      [alert setCancelButtonWithTitle:@"OK" block:nil]; 
      [alert show]; 
     } 
     else if (error != nil){ 
      [loadingView removeFromSuperview]; 
      loadingView = nil; 
      BlockAlertView *alert = [BlockAlertView alertWithTitle:@"Network Error" message:@"There was a problem connecting to the network.\nPlease check your internet connection and try again."]; 
      [alert setCancelButtonWithTitle:@"OK" block:nil]; 
      [alert show]; 
     } 
    }]; 

回答

0

好的解決了這個問題。與我正在使用的委託指派有關的問題是,我通知我的觀點,我完成了處理/保存響應數據並執行賽格。由於代理正在viewDidLoad中設置,當下一個視圖出現並接管委託時,登錄視圖失去了委託控制。只需將委託任務移至viewWillAppear(或viewDidAppear)。

相關問題