UITabBarItem.title与UINavigationController.title [英] UITabBarItem.title vs. UINavigationController.title

查看:70
本文介绍了UITabBarItem.title与UINavigationController.title的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为UITabBarItem分配了一个标题(initWithTitle),并将其连接到UINavigationController.

I allocated a UITabBarItem with a title (initWithTitle) and connected it to a UINavigationController.

我发现,如果导航控制器的根视图控制器具有其自己的标题,则该标题将永久替换选项卡栏项上指定的标题.例如,如果选项卡栏项目的标题设置为ONE,并且导航控制器的根视图控制器的标题设置为两个,则选项卡栏项目始终显示两个,而不是一个.使选项卡栏项显示为ONE的唯一方法是完全省略导航控制器的根标题.

I found out that if the navigation controller's root view controller has its own title, then that title permanently replaces the title specified on the tab bar item. For example, if the tab bar items' title is set to ONE and the navigation controller's root view controller's title is set to TWO, the tab bar item always shows TWO, not ONE. The only way to have the tab bar item show ONE is to omit the navigation controller's root title altogether.

问题是,我希望每个标题都有不同的标题,因为选项卡栏项并不总是指向导航控制器的根视图控制器-它显示了被推到导航控制器上的最后一个视图控制器,这意味着标签栏上的根标题可能不合适.另一方面,我不能只在导航控制器中扔掉标题,因为标题用在导航栏上.渔获量为22.

The thing is, I want to have different titles for each, because the tab bar item doesn't always lead to the navigation controller's root view controller - it shows the last view controller that was pushed onto the navigation controller, which means that the root's title on the tab bar may be inappropriate. On the other hand, I can't just throw away the title in the navigation controller, because it is used on the navigation bar. Sort of Catch 22.

有没有解决的办法?

推荐答案

我经常使用带有tabBar的navigationBar,几乎从来没有相同的标题.我使用过的代码(在init中)为:

I often use a navigationBar with a tabBar and almost never have the same title. The code I've used (in init) reads:

// SET TAB BAR NAME AND IMAGE
[[self tabBarItem] setTitle:@"Short Title"];
[[self tabBarItem] setImage:[UIImage imageNamed:@"MyImage.png"]];

// SET NAVIGATION
[[self navigationItem] setTitle:@"Much Longer Title"];  

我从来没有遇到过这个问题.

I've never encountered a problem with this.

这篇关于UITabBarItem.title与UINavigationController.title的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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