views:

68

answers:

1

Situation:
I have an Xcode project based on the "Navigation-Based-Application" template. So that means I have a SINGLE UINavigationController that manages a UIViewController.

What I want To Do:
What I want to do is add one more UINavigationController to my project -- and be able to switch back and forth between them. (I want to do this to make space for some seperate unrelated content so that it does not have a back button pointing back to the root view controller.)

Question:
How do I add one more UINavigationController to my project and switch between the two UINavigationControllers?

+1  A: 

The most common, and natural iPhone OS, way of doing this is to add a UITabBarController to your application. The Xcode template Tab Bar Application will guide you in the right direction on how to use it.

But...

If you don't like to have a Tab Bar in your application, and wish to switch between different UINavigationController instances (or any UIViewController for that matter), you can do something like this.

First you need to create your UINavigationController instances in a appropriate place (for example a new view controller, or in you Application Delegate, if you want to take the easy way out). You can then switch between controllers by just swapping which Navigation Controller's view that should be visible.

Example in the Application Delegate, "firstNavigationController" and "secondNavigationController" are UINavigationController instance variables:

- (void)showFirstNavigationController {
    [secondNavigationController.view removeFromSuperview];
    [self.window addSubview:firstNavigationController.view];
}

This will simply display the first instead of the second Navigation Controller. Note that this example is very simple. I didn't take into consideration that you should correctly handle the methods viewWillAppear:, viewDidAppear: and so on.

alleus
Thanks -- and for extra credit: How can I make the transition smooth (or animated)?
RexOnRoids
You can accomplish that easy with some basic `UIView` animations. Before the first row in my method, add: `[UIView beginAnimations:@"myFlip" context:NULL];` and `[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];` And in the bottom: `[UIView commitAnimations];`
alleus