向导航栏添加标题
我将两个不同的视图控制器添加到 TabBarController 的视图控制器数组中,并将此 TabBarController 添加到导航控制器中。
现在我想在导航控制器上的选项卡栏中为不同视图显示不同的标题。
任何帮助将不胜感激。
I have two different view controllers added to the view controllers array of a TabBarController and this TabBarController is added to a Navigation Controller.
Now I want to show different title for different views in the tabbar, on the navigationController.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
导航栏中的标题取自其顶部视图控制器的导航项。在您的情况下,听起来它的顶视图控制器是选项卡栏控制器,因此每当选项卡栏发生变化时,您都需要设置选项卡栏控制器的标题。
具体来说,您需要将
UITabBarControllerDelegate
分配给选项卡栏控制器的delegate
属性并实现以下方法:该行相当于
因此您可以使用其中任何一个。无论如何,将各个选项卡视图控制器的标题设置为您想要的任何标题,然后标题将在选项卡更改时更改。
the title within the navigation bar is taken from the navigation item from it's top view controller. It sounds like its top view controller, in your case, is the tab bar controller, so you'll want to set the title of the tab bar controller whenever the tab bar changes.
Specifically, you'll want to assign a
UITabBarControllerDelegate
to the tab bar controller'sdelegate
property and implement the following method:The line is equivalent to
So you can use either one. Any way, set the titles of the individual tab view controllers to whatever title you want, and then the title will change when the tabs change.
假设您有三个视图控制器,具有三个不同的视图,并且您想要更改导航栏的标题,当您推送第二个视图控制器时,当您推送第三个视图控制器时相同:
这样我们可以在推送下一个视图控制器时更改导航栏的标题。
希望有帮助。
Suppose you have three viewcontrollers having three different view and you want to change the title of navigation bar,when you are pushing secondViewcontroller and same when you are thirdviewcontroller then:
This way we can change the title of navigation bar while pushing some next view controller.
Hope it helps.