2017-04-06 97 views
0

當用戶從UIAlertController彈出窗口中單擊「確定」按鈕時,它將返回到先前的視圖控制器。我堅持如何。下面是我的代碼。如何返回到前一個視圖控制器?

if (jsonData == nil){ 
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error!" message:@"This Git repository is empty" preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]; 
    [alertController addAction:ok]; 

    [self presentViewController:alertController animated:YES completion:nil]; 

     } 

回答

1

試試這個 -

if (jsonData == nil){ 
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error!" message:@"This Git repository is empty" preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ 
      // Ok action example 
      [self.navigationController popViewControllerAnimated:YES]; 
     }]; 
     [alertController addAction:ok]; 

     [self presentViewController:alertController animated:YES completion:nil]; 
    } 
+0

Awesome..its工作..日Thnx sir..almost2小時我在找這個答案! –

+0

很高興爲您效勞。 –

+0

完成upvote @Dipankar Das :) –

相關問題