How to include tabbar and navigation controller in single app?
How to create a tabbar Controller and Navigation Bar Controller in a 开发者_如何学运维window based app? I am trying to include both controllers.
You can do this as follows... Create project of navigationController type.. then in AppDelegate , create a tabBarController. Have an array of you Viewcontrollers as follows...
mTabBar = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
TSDetailTaskController *mTSDetailTaskController = [[TSDetailTaskController alloc]initWithNibName:@"TSDetailTaskController" bundle:nil];
UINavigationController *mTaskNavBar=[[UINavigationController alloc]initWithRootViewController:mTSDetailTaskController];
mTaskNavBar.tabBarItem.title=@"Task List";
mTaskNavBar.tabBarItem.image =[UIImage imageNamed:@"glyphicons_114_list.png"];
[mTSDetailTaskController release];
mTSSearchController=[[TSSearchController alloc]initWithNibName:@"TSSearchController" bundle:nil];
UINavigationController *mSearchNavBar=[[UINavigationController alloc]initWithRootViewController:mTSSearchController];
mSearchNavBar.title=@"Search";
mSearchNavBar.tabBarItem.image=[UIImage imageNamed:@"glyphicons_009_search.png"];
[mTSSearchController release];
TSSettingController *mTSSettingController = [[TSSettingController alloc]initWithNibName:@"TSSettingController" bundle:nil];
UINavigationController *mSettingNavBar=[[UINavigationController alloc]initWithRootViewController:mTSSettingController];
mSettingNavBar.tabBarItem.title=@"Setting";
mSettingNavBar.tabBarItem.image=[UIImage imageNamed:@"glyphicons_280_settings.png"];
[mTSSettingController release];
[localViewControllersArray addObject:mTaskNavBar];
[localViewControllersArray addObject:mSearchNavBar];
[localViewControllersArray addObject:mSettingNavBar];
[mTaskNavBar release];
[mSearchNavBar release];
[mSettingNavBar release];
mTabBar.viewControllers = localViewControllersArray;
mTabBar.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);
[localViewControllersArray release];
[window addSubview:mTabBar.view];
[self.window makeKeyAndVisible];
return YES;
hope this will help you out..
Instead of viewcontrollers, add navigation contollers as each item for the tabbarcontroller.
You can also do it in the Interface Builder, just make sure the Tabbar controller is the root/master controller and inside it you can add as many navControllers as you need. Of course, the tabbar controller is the one added to the Window in the AppDelegate.m file.
I you dont want the tabbar to be visible from the begining, you can implement self.tabbarcontroller.tabbar.hidden = YES;
in the viewDidLoad or viewWillAppear
methods of each of the views you dont want the tabbar on.
精彩评论