UINavigationBar-以编程方式设置标题? [英] UINavigationBar - Set title programmatically?

查看:53
本文介绍了UINavigationBar-以编程方式设置标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签栏应用程序,每个标签上都有不同的视图.每个视图都有一个UINavigationBar,其标题在Interface Builder上设置.我想根据ViewDidLoad方法中的子句更改标题,所以如果x {更改标题}.

I have a tab bar application with a different view on each tab. Each view has a UINavigationBar with title set on Interface Builder. I want to change the title based on a clause in the ViewDidLoad method, so if x { change the title }.

我尝试过self.title = @"title",但这会更改选项卡栏项本身的标题.

I have tried self.title = @"title", but this changes the title of the tab bar item itself.

那么,这是怎么做到的?

So, how is this done?

推荐答案

我已经使用类似以下代码的方式以编程方式设置了标题:

I've set the title programmatically using code something like this:

navBar.topItem.title = @"title";

其中navBar被声明为链接到界面构建器中导航栏的IBOutlet UINavigationBar.这在我的应用程序中有效;但是,我没有使用标签栏.

where navBar is declared as an IBOutlet UINavigationBar linked to the navigation bar in interface builder. This worked in my app; however, I was not using a tab bar.

如果navBar.topItem是选项卡栏项,则由于navBar的topItem和选项卡,我看不到在不更改选项卡栏项的标题的情况下更改导航栏上显示的标题的方法栏项目是同一对象.

If navBar.topItem is the tab bar item, I don't see a way for you to change the title that appears on the navigation bar without also changing the title on the tab bar item, since the navBar's topItem and the tab bar item is the same object.

这篇关于UINavigationBar-以编程方式设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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