简体   繁体   中英

How to change the View the back-button is calling?

I have a navigation controller in my application. Now I am having a viewcontroller, where the back-button of the navigation-bar should not go to the previous viewcontroller. I want that if someone press this back-button, my first viewcontroller (MainMenu) is called. Is it possible to do this without using a BarButtonItem?

Example: VC1 = MainMenu -> VC2 -> VC3

Now if I press the back-button of VC3, I want to go to VC1!!!! (normally I get back to VC2)=

UINavigationController has a property called viewControllers of type NSArray. After pushing the third one, your navigation controller's viewControllers has 3 VC's (VC1, VC2, VC3). You can make a new array containing VC1 and VC3, and set it to the viewControllers property. That way the previous VC in the stack will be VC1 and after pressing the back button you will go to VC1, not VC2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM