根据选择的选项卡更改导航栏的标题? [英] Change title of navbar based on which tab is selected?

查看:30
本文介绍了根据选择的选项卡更改导航栏的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iOS 应用程序,其中有一个导航控制器作为根控制器,但有一个选项卡栏可以在其中一个导航栏中的视图之间进行选择.它看起来类似于 iTunes 应用程序(顶部的导航栏,底部的标签栏).我希望导航栏的标题根据选择的选项卡进行更改.每个选项卡都有两个单独的控制器文件.以下是我迄今为止尝试使用的方法来解决此问题,但无济于事:

I have an iOS app where there is a navigation controller as the root controller but at one part there is a tab bar to select between views in one of the nav bars. It looks similar to the iTunes app (navigation bar on top, tab bar on the bottom). I want the title of my navigation bar to change based on which tab is selected. I have two separate controller files for each tab. Here is what I have tried to use in each so far to fix this to no avail:

self.navigationItem.title = @"Title";
self.navigationController.navigationItem.title = @"title";
[self.navigationController setTitle:@"Live"];    
[self setTitle:@"Top Title"];

如何根据按下的选项卡更改导航栏标题?

How do I change the NavBar title based on which tab is pressed?

推荐答案

您在当前显示的视图控制器中更改栏的标题.

You change the title of the bar in the view controller that is currently being displayed.

因此,例如,在您在选项卡控制器中显示的视图控制器 A 中,您可以添加:

So for example, in view controller A that you're showing in the tab controller, you might add:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    [self setTitle:@"A"];
    self.tabBarController.navigationItem.title = @"A";
}

B、C 等也是如此.

这篇关于根据选择的选项卡更改导航栏的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆