2016-05-18 53 views
1

我已經創建了請求,並且我想在彈出對話框時收到成功消息。這裏是我的代碼:popViewController在iOS中的NSURLSessionDataTask塊中不起作用

NSURLSession *session = [NSURLSession sharedSession]; 
NSString *baseURLRequest = [NSString stringWithFormat:@"%@/email_addr=%@",mySession.baseURL,self.txtEmail.text]; 
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:baseURLRequest] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; 
    NSDictionary *dict = [json objectForKey:@"result"]; 
    NSString *msg = [dict objectForKey:@"msg"]; 

     if ([[dict objectForKey:@"status"] isEqualToString:@"success"]) 
     { 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [self showMesssgeonAlert:@"Success"]; 
       [self hideProgress]; 

       [self.navigationController popViewControllerAnimated:YES]; 
      }); 
     } 
     else 
     { 
     } 
}]; 
[dataTask resume]; 

下面不工作,

[self.navigationController popViewControllerAnimated:YES]; 

有沒有人有一個想法,爲什麼發生這種情況? UINavigation controller對於viewControllers也是相同的。請幫助我,謝謝。

+0

檢查是否([[dict objectForKey:@「status」] isEqualToString:@「success」])成功並檢查自己是否自己.navigationcontroller不爲零 – Rajesh

+1

檢查'self.navigationController'是否爲零 –

+0

if self showMesssgeonAlert:@「Success」];和[self hideProgress];方法被稱爲善意檢查你的navigationController可能是零。你有嵌入導航控制器的故事板。 – luckyShubhra

回答

-2

@DevTest你不能把[self.navigationController popViewControllerAnimated:YES];在隊列中,隊列不會彈出viewcontroller,所以你會列出side dispatch隊列...

+0

它在'dispatch_async(dispatch_get_main_queue()'裏面,這是正確的。 –

相關問題