如何将TabbarController添加到NavigationController

时间:2014-11-12 10:03:55

标签: ios objective-c uitabbarcontroller

我有一个带有navigationController和storyboard的项目。 现在我需要添加另一个项目(结合两个项目) 我想使用TabbarController在两个navigationControllers之间切换。 我怎么能意识到这一点?

1 个答案:

答案 0 :(得分:1)

在AppDelegates视图控制器中放下此代码: -

 @implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UITabBarController *tabBar = [[UITabBarController alloc] init];

    ViewController *homeVC = [[ViewController alloc] init];
    homeVC.tabBarItem.title = @"Home";
    homeVC.tabBarItem.image = [UIImage imageNamed:@"Home-icon.png"];
    UINavigationController *HomeNavi = [[UINavigationController alloc] initWithRootViewController:homeVC];

    settingViewController *settingVC = [[settingViewController alloc] init];
    settingVC.tabBarItem.title = @"Setting";
    settingVC.tabBarItem.image = [UIImage imageNamed:@"Setting-icon.png"];
    UINavigationController *settingNavi = [[UINavigationController alloc] initWithRootViewController:settingVC];

    tabBar.viewControllers = [NSArray arrayWithObjects:HomeNavi,settingNavi, nil];
    HomeNavi.navigationBarHidden = YES;
    settingNavi.navigationBarHidden = YES;
    [self.window makeKeyAndVisible];
    self.window.rootViewController = tabBar;
    // Override point for customization after application launch.
    return YES;
}