无法在TabViewController上添加NavigationBar

时间:2013-12-08 22:25:06

标签: iphone ios7

我无法在TabView控制器上看到导航栏。 我试图添加两个标签。 类层次结构如下所示。

请帮忙。

ViewControllerOne : UIViewController
ViewControllerTwo : UIViewController
TabViewController : UITabBarController

    ViewControllerOne *viewFirst = [[ViewControllerOne alloc]init];
    ViewControllerOther *viewSecond = [[ViewControllerOther alloc]init];


    [self.tabBarController.navigationController setViewControllers:@[viewFirst, viewSecond]];
    [self.tabBarController.navigationController setTitle:@"TITLE TITLE"];

    viewFirst.title=@"ONE";
    viewFirst.tabBarItem.image = [UIImage imageNamed:@"first.png"];
    viewSecond.title=@"TWO";
    viewSecond.tabBarItem.image = [UIImage imageNamed:@"second.png"];
    viewFirst.view.backgroundColor = [UIColor grayColor];
    viewSecond.view.backgroundColor = [UIColor whiteColor];

    self.viewControllers = [NSArray arrayWithObjects:viewFirst, viewSecond, nil];

1 个答案:

答案 0 :(得分:1)

我不确定“自我”是什么,但看起来它只是一个随机视图控制器。关于这方面的更多背景会很好,但我会尝试一些想法。

看起来您正在尝试将viewFirst和viewSecond设置为导航堆栈,而不是两个不同的选项卡。看起来您还没有将这些控制器放在UINavigationControllers中。从这些方面尝试更多的东西:

ViewControllerOne *one = [[ViewControllerOne alloc] init];
one.title = @"ONE";
one.tabBarItem.image = [UIImage imageNamed:@"first.png"];
one.view.backgroundColor = [UIColor grayColor];
UINavigationController *navOne = [[UINavigationController alloc] initWithRootViewController:one];
ViewControllerTwo *two = [[ViewControllerOne alloc] init];
two.title = @"SECOND";
two.tabBarItem.image = [UIImage imageNamed:@"second.png"];
two.view.backgroundColor = [UIColor whiteColor];
UINavigationController *navTwo = [[UINavigationController alloc] initWithRootViewController:two];
TabViewController *tabController = [[TabViewController alloc] init];
[tabController setViewControllers:@[navOne, navTwo] animated:NO];

确保tabController是关键UIWindow的根视图控制器。