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

查看:38
本文介绍了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.

实现我想做的正确方法是什么?

What is 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).

由于笔尖是从创建视图控制器开始的(假设您已经在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天全站免登陆