2010-01-21 61 views

回答

187

UINavigationController-popViewControllerAnimated:方法相反應該做你想要什麼:

[navigationController popViewControllerAnimated:YES]; 
+12

真棒,感謝史蒂夫和尼爾斯。我使用的解決方案是\t \t [self.navigationController popViewControllerAnimated:YES]; 簡單;) – oberbaum 2010-01-21 08:54:19

+0

這工作很好,除了在uitabbar上添加viewcontrollers。任何線索? – virata 2012-01-05 11:40:44

+1

我添加了'[self.navigationController popViewControllerAnimated:YES];'但它什麼都沒做,但是在貼上正在工作的按鈕時有一個提醒。 – 2013-07-16 11:23:54

7

你應該叫

popViewControllerAnimated:

這是添加視圖控制器與pushViewController:animated:

24

假設你實際上並不想按程序按鈕,但si mply複製按下按鈕的結果,你應該告訴導航控制器彈出當前視圖控制器。

[self.navigationController popViewControllerAnimated:YES];

這將從堆棧中刪除,並返回到上一個視圖控制器。

6
[self.navigationController popViewControllerAnimates:YES]; 

是最好的選擇,但如果你也不在同一個視圖控制器類或者叫那麼你的後退按鈕方法之前,你委託的變化也可以try--

首先你必須定義後退按鈕---

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"anyTitleForBackButton" style: UIBarButtonItemStyleBordered target: nil action: @selector(backButtonTapped)]; 

[[self navigationItem] setBackBarButtonItem: newBackButton]; 

[newBackButton release]; 

,然後在backButtonTapped方法,你可以call--

[self.navigationController pushViewController:desiredViewController animated:YES]; 
20

夫特3.0

回到根視圖

self.navigationController?.popToRootViewController(animated: true) 

回到前一視圖

self.navigationController?.popViewController(animated: true) 

夫特2。3

回到根視圖

self.navigationController?.popToRootViewControllerAnimated(true) 

回到以前的觀點

self.navigationController?.popViewControllerAnimated(true) 
+0

不錯的答案,我正在尋找它 – 2016-01-22 14:01:33

+0

謝謝!快樂它幫助.. – 2016-01-22 14:02:33

相關問題