Reputation: 271
In AppDelegate.m I am writing following code for navigationbar.
MaterialsListViewController *materials = [[MaterialsListViewController alloc]initWithNibName:@"MaterialsListView" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:materials];
In the same AppDelegate.m I am writing following code for tabbar.
UIViewController *viewController1, *viewController2;
viewController1 = [[[MaterialsListViewController alloc] initWithNibName:@"MaterialsList" bundle:nil] autorelease];
viewController2 = [[[RecentMaterialsListViewController alloc] initWithNibName:@"RecentMaterialsList" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
NSArray *items = self.tabBarController.tabBar.items;
UITabBarItem *item1 = [items objectAtIndex:0];
[item1 setTitle:@"Materials"];
UITabBarItem *item2 = [items objectAtIndex:1];
[item2 setTitle:@"Recent"];
self.window.rootViewController = self.tabBarController;
How to add NavigationBar to the tabbar?
Upvotes: 1
Views: 526
Reputation: 17186
In the below line, you can pass navigationcontroller
as a member of the array.
self.tabBarController.viewControllers = [NSArray arrayWithObjects: navigation, viewController2, nil];
Upvotes: 1
Reputation: 2988
You are missing the UINavigationController
.
After you cretae viewController1
init a UINavigationController
with a your viewController has RootViewController:
UINavigationController *navigationController_01 = [[UINavigationController alloc] initWithRootViewController:(UIViewController *)];
Then add the navigationController_01
to tabBarController.viewControllers
:
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController_01, navigationController_02, nil];
Upvotes: 3