iphone – 独立于TabBar标题设置NavController标题

我正在通过编程方式构建视图控制器及其相关导航控制器的相当典型的过程,然后将导航控制器添加到tabBarController.

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
[self.tabBarController setHidesBottomBarWhenPushed: YES];

FirstViewController * firstView = [[[FirstViewController alloc] init] autorelease];
firstView.title = @"First";
firstView.tabBarItem.image = [UIImage imageNamed:@"icon_first_view.png"];
UINavigationController * firstViewNav = [[[UINavigationController alloc] initWithRootViewController:firstView] autorelease];

[tabBarController setViewControllers:[NSArray arrayWithObjects: firstViewNav, nil]];

这很好用,NavigationController标题和TabBar标题会说“First”.现在,我想将导航控制器标题更改为“FooBar”,并将标签栏标题保留为“First”.

我试过了:

firstViewNav.navigationItem.title = @"FooBar";

但这似乎并没有改变它.如果我在由此导航控制器(firstView.title)管理的实际ViewController上更改标题,则TabBar标题和Navbar标题都会更改,这是不希望的.

有任何想法吗?

最佳答案 只需隐藏NavigationBar并添加一个包含所需标题的工具栏.

点赞