Iphone – How to replace a viewController in the NavigationController Stack

iphoneuinavigationcontrolleruiviewcontroller

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

Best Answer

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

Related Topic