简体   繁体   English

如何在单个应用程序中包含tabbar和导航控制器?

[英]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. 你可以这样做...创建navigationController类型的项目..然后在AppDelegate中,创建一个tabBarController。 Have an array of you Viewcontrollers as follows... 有一组ViewControllers如下...

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.. 希望这会帮助你...

而不是视图控制器,添加导航控制器作为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. 您也可以在Interface Builder中执行此操作,只需确保Tabbar控制器是根/主控制器,在其中您可以根据需要添加任意数量的navController。 Of course, the tabbar controller is the one added to the Window in the AppDelegate.m file. 当然,tabbar控制器是添加到AppDelegate.m文件中的Window的控制器。 I you dont want the tabbar to be visible from the begining, you can implement self.tabbarcontroller.tabbar.hidden = YES; 我不希望tabbar从开始就可见,你可以实现self.tabbarcontroller.tabbar.hidden = YES; in the viewDidLoad or viewWillAppear methods of each of the views you dont want the tabbar on. 在每个视图的viewDidLoad或viewWillAppear方法中,您不希望使用tabbar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM