Change title of navbar based on which tab is selected?(根据选择的选项卡更改导航栏的标题?)
问题描述
我有一个 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 等也是如此.
这篇关于根据选择的选项卡更改导航栏的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:根据选择的选项卡更改导航栏的标题?


基础教程推荐
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- iOS4 创建后台定时器 2022-01-01