0
votes

I've just worked through a tutorial on how to create a Navigation controller starting with a Window-Based application project.

Now, I'm trying to figure out how to applied the methods I used in the tutorial with a root view that has a tab bar controller.

I've set up a tab bar controller, again using the window-based app project, and added four tab bar items that are linked to their respective UIViewController classes/nib.

Can I add a nav controller like I did with my window-based tutorial to the UIViewController classes?

Here is how i created a nav controller by itself:

#import <UIKit/UIKit.h>

@interface NavAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end




#import "NavAppDelegate.h"

@implementation NavAppDelegate

@synthesize window;
@synthesize navController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [self.window addSubview:navController.view];
    [window makeKeyAndVisible];

    return YES;
}



etc...
1
Go to your Interface Builder and look at the tab bar controller. There you have got your four tabs and for each tab you probably have a view controller. Instead of having a view controller, try dragging a navigation controller on top of your tab bar and remove your previous view controllers. Now you should have navigation controller with a view controller inside of it.simonbs

1 Answers

10
votes

Both UINavigationController and UITabBarController are controllers of controllers, i.e. they manage multiple UIViewControllers. The UIViewControllers in turn manage the views. So the title of your question does need revision.

The standard setup is this: UITabBarController is the root controller. Each tab controls either a UIViewController or a UINavigationController which in turn manages UIViewControllers.

So you add UIViewControllers or UINavigationControllers to your tab bar items.

Thus, the direct answer to your question is: no. You cannot add a UINavigationController to your UIViewControllerbut rather the other way round.