Ios – Dismiss pushed view from within Navigation Controller

iosiphoneuiviewcontrollerxcode

I have a Navigation Controller with a View Controller displaying a button. The button is linked to another View Controller using a push segue which automatically adds a top navigation bar with a back button. This all works fine. Pressing the back button slides off the 2nd view and returns to the 1st.

I have a button on the 2nd View Controller, that when pressed runs some code and a delegate call back to the 1st View Controller. Again this works fine.

Now I just need to dismiss the 2nd pushed View from code as if the back button was pressed.
I have tried using dismissModalViewCcontrollerAnimated and dismissViewControllerAnimated, however they both dismiss the whole Navigation Controller which removes view 2 and 1 (returning bak to my main menu).

Whats the correct way to slide off the view.

Best Answer

Obtain a reference to your UINavigationController and call

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

on it.

Related Topic