1
votes

How to install a NavigationController as the root view in a tab bar view?

In my applicaton:didFinishLaunchingWithOptions: method I created a tab bar interface, setting the rootViewController of the window as the tabBarController.

Now, in one of my tab bar views, I want to add a navigation bar at the top. How can I accomplish this?

Should I subclass navigationcontroller?

Thanks

3
Don't forget to accept an answer.shutdown_r_now

3 Answers

2
votes

It sounds like you're doing it in code, not IB, so here's what you can do.

// First create your RootViewController:
UIViewController *rootViewController = [[UIViewController alloc] init];
// Then add the rootViewController to a UINavigationController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
// Now your RootViewController is a UINavigationController
// Add it to your UITabBarController
[tabBarController.viewControllers addObject:navigationController];
// You can now get rid of the RootViewController and UINavigationController
[rootViewController release];
[navigationController release];
1
votes

You can do this in the Interface Builder. Replace the view controller inside the tab bar controller with a navigation controller. Then set the class and Nib name of the view controller (inside the navigation controller) to your root class.

0
votes

You have to first create a UITabbarController application, then go to MainWindow.xib file. By default two tab view will be created.

Check the attribute property of the tab bar and change the view to RootViewController. You will have to set the class name and xib file name to RootViewController.