1
votes

I've got a hierarchy of 3 ViewControllers on a UINavigationController app.

Start in VC1, from there you can load VC2. In VC2 you can load VC3.

You can navigate backwards through the VC's by pressing the left nav button on the navbar.

But the designer wants to be able to jump from VC1->VC3, and then if you press the left navbar button to go back it will take you to vc2.

Is it possible to have have this kind of navigation with a NAV controller?

If the user wants to go VC1-VC3 can i push both VC2 and then VC3 onto the navigationController stack so that the navigation is maintained correctly.

Also if the user wants to go from VC3->VC1 can i pop both VC3 and then VC2 off the navigationController stack so that VC1 displays?

3
I'm not sure if it's even possible to do what you're asking, but might it not be better to animate VC2 in first, then instantly VC3? This way the user sees VC2 jump past. By seeing that, the user won't be surprised when the navigation path they went through is suddenly different when going back (which is what could happen in the situation you describe now). - Aberrant

3 Answers

3
votes

First - tell your designers that this kind of navigation is confusing for the users and they should take some more usability and UX classes. Second - yes it's possible - the easiest way would be to call

[navigationController setViewControllers:newViewControllers animated:YES];

This will replace the entire navigation stack, so ensure that it contains [VC1, VC2, VC3] (and whatever else might happen to be before them)

1
votes

The normal back button will pop to the previous view controller. You could make a left bar button in you V3 which will pop to a given view controller in your hierarchy using the UINavigationController method (giving your V1 instance as viewController)

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
0
votes

Push BOTH VC2 and VC3 onto the stack to preserve the navigation when pressing the back button. To go from VC3 to VC1 you can use...

[navigationController popToViewController:vc1 animated:YES];

or if VC1 is the root...

[navigationController popToRootViewControllerAnimated:YES];