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 等也是如此.
这篇关于根据选择的选项卡更改导航栏的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:根据选择的选项卡更改导航栏的标题?
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
