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

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

问题描述

我有一个标签栏应用程序,每个标签上都有不同的视图。每个视图都有一个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 am wanting to change the title based on a clause in the ViewDidLoad method, so if x { change the title }.

我试过 self.title = @title,我在Stackoverflow上读过 - 但是这个改变了标签栏项目本身的标题。

I have tried self.title = @"title" , which I read here on Stackoverflow - but this changes the title of the tab bar item itself.

那么,这是怎么做到的?

So, how is this done?

推荐答案

我是使用以下代码以编程方式设置标题:

I've set the title programatically 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 - 以编程方式设置标题? iPhone SDK 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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