Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace a viewController in the NavigationController Stack?

I have a navigationController, I push a new viewController onto it's stack, I have been trying to figure out a way to switch this ViewController with another viewController from within the first ViewController.

I have 3 almost identical views, depending on the user interaction I would like to be able to switch between these views within the same stack index i.e. without pushing or popping views on the navigationController.

So if view C has index 3 on the navigationController stack and the user taps a certain button in view C the C1 view replaces C on the stack and gets index 3.

I have been through the UINavigation Class and can't find a way around this. If I popViewController from within the current viewController and the tries to pushViewController… well that can't be done as the viewController gets released when popping it. If I instead try to do pushViewController, well then I gets added on top of my current viewController.

I hope it makes sense and that someone can help me out:)

Thanks

like image 556
RickiG Avatar asked Dec 18 '22 04:12

RickiG


1 Answers

You can assign an NSArray of controllers to the viewControllers property to alter the entire stack instantaneously.

like image 62
Neil Mix Avatar answered May 24 '23 20:05

Neil Mix