UITabBarItem.title 与 UINavigationController.title
我分配了一个带有标题 (initWithTitle) 的 UITabBarItem 并将其连接到 UINavigationController。
我发现,如果导航控制器的根视图控制器有自己的标题,那么该标题将永久替换选项卡栏项目上指定的标题。例如,如果选项卡栏项目的标题设置为“一”,并且导航控制器的根视图控制器的标题设置为“二”,则选项卡栏项目始终显示“二”,而不是“一”。让选项卡栏项目显示 ONE 的唯一方法是完全省略导航控制器的根标题。
问题是,我希望每个标题都有不同的标题,因为选项卡栏项目并不总是导致导航控制器的根视图控制器 - 它显示了被推送到导航控制器上的最后一个视图控制器,这意味着根的标签栏上的标题可能不合适。另一方面,我不能直接丢弃导航控制器中的标题,因为它用在导航栏上。有点像第 22 条军规。
有办法解决这个问题吗?
I allocated a UITabBarItem with a title (initWithTitle) and connected it to a UINavigationController.
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.
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.
Is there a way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我经常将导航栏与选项卡栏一起使用,并且几乎从不具有相同的标题。我使用的代码(在
init
中)显示:我从未遇到过这样的问题。
I often use a navigationBar with a tabBar and almost never have the same title. The code I've used (in
init
) reads:I've never encountered a problem with this.
嗯,这就是我发现的。
似乎如果你这样做:
然后,在推送到主视图的根视图控制器中,你会这样做:
然后发生的事情就是我上面描述的。
但如果我在 main 的根视图控制器中添加以下行,我可以修复它:
这似乎是一个“计时”问题。
Well, here's what I found out.
It seems that if you do:
and then, in the root view controller pushed to main, you do:
then what happens is what I described above.
But I can fix it if I add the following line in the root view controller of main:
It seems to be sort of a "timing" issue.
UINavigationController
是UITabBarController
的viewControllers
之一。因此,设置UINavigationController
的tabBarItem.title
,它会覆盖UINavigationController
的rootViewController
的值。UINavigationController
将其navigationBar
的标题设置为其topViewController.title
。The
UINavigationController
is one of theviewControllers
of theUITabBarController
. Therefore, set thetabBarItem.title
of theUINavigationController
, which overrides that of theUINavigationController
'srootViewController
. TheUINavigationController
sets itsnavigationBar
's title to itstopViewController.title
.