iPhone Objective-C:以编程方式更改使用IB创建的标签栏中标签栏项目的标题? [英] iPhone Objective-C: Programatically change title of tab bar item in tab bar created using IB?

查看:109
本文介绍了iPhone Objective-C:以编程方式更改使用IB创建的标签栏中标签栏项目的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我在标签的根视图的viewDidLoad中设置标题,只有在我单击选项卡时才会更改标题。我想在选择标签之前设置它。我试过类似的东西:

Right now, I am setting the title in the viewDidLoad of the root view of the tab, which only changes when I click on the tab. I want this to be set before I select the tab. I tried something like:

[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] title] = @"string";

在第一个加载另一个标签的视图中,但是因为我左边有明显的错误操作数错误。

in the first view that loads in another tab, but there is clearly something wrong since I get a left operand error.

有人能告诉我实现我想做的正确方法吗?

Can somebody show me the correct way to achieve what I am trying to do?

谢谢!!

推荐答案

尝试在awakeFromNib中设置标题而不是viewDidLoad。在您需要视图之前,视图控制器的视图实际上并未加载,并且默认情况下标签栏控制器在您实际选择它之前不会访问视图控制器的视图(这就是您在选择时看到标题更改的原因选项卡)。

Try setting the title in awakeFromNib instead of viewDidLoad. The view for a view controller is not actually loaded until you need the view, and the tab bar controller by default doesn't access the view of a view controller until you actually select it (which is why you saw the title change when you selected the tab).

由于nib正在创建视图控制器以开始(假设您已在IB中构建了标签栏控制器),将立即调用awakeFromNib视图控制器已经构建,在标签栏控制器可以询问标题是什么之前。

Since the nib is creating the view controller to start with (assuming you have built your tab bar controller in IB) awakeFromNib will be called as soon as the view controller has been built, before the tab bar controller can ask what the title is.

这篇关于iPhone Objective-C:以编程方式更改使用IB创建的标签栏中标签栏项目的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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