Reputation: 9049
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...
Upvotes: 0
Views: 4331
Reputation: 80271
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 UIViewController
but rather the other way round.
Upvotes: 10