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

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

问题描述

我的应用基于标签栏架构。为了拥有一个简单的国际化机制,我不会在XIB文件中写任何字符串。 viewdidload允许以编程方式更改视图中的字符串。

My app is based on a tab bar architecture. In order to have an easy internationalisation mechanic, I do not write any string in XIB files. viewdidload permits to change programmaticaly the strings in the views.

当我的应用程序启动时,我可以看到4个选项卡。但事实上只有第一个加载其视图控制器。其他人等待用户点击加载。
标签标题可以使用[self setTitle:@Mouhahaha]更改;在加载视图控制器的viewDidLoad中。

When my app launches, I can see the 4 tabs. But in fact only the first one loads its view controller. The others wait for user click to be loaded. Tabs title can be changed using [self setTitle:@"Mouhahaha"]; in viewDidLoad of loaded view controller.

如果我想保持我的国际化机制,我不会在我的XIB中设置tabbar项的名称。但是,在开始时,所有选项卡的视图控制器都没有加载,我有一些选项卡的空白标题。只有当用户点击选项卡时才会设置正确的标题。

If I want to keep my internationalisation mechanic available, I do not set in my XIB the name of tabbar items. But, as at start all tab' view controllers are not loaded, I have blank titles for some tabs. The right title is set only when the user click on the tab.

我正在寻找一种方法来为每个tabbaritem设置此标题programaticaly。你有提示吗?

I am looking for a way to set this title programaticaly for each tabbaritem. Do you have hints ?

非常感谢。

kheraud

推荐答案

你需要做的就是创建一个UITabBarController实例,然后在其中分配你想要的任何视图,然后设置UITabBarController视图。确保您的TabBarController是可见的。还要确保使用 #import 导入标签栏中所需的任何viewControllers。

All you need to do is make an instance of UITabBarController, then alloc any views you want in it, then set the UITabBarController views. Make sure that your TabBarController is the one that is visible. Also make sure that any viewControllers you want in your tab bar are being imported with #import.

UITabBarController *c = [self tabBarController];
SecondViewController *s = [[SecondViewController alloc] init];
[s setTitle:@"Whatever"];
c.viewControllers = [NSArray arrayWithObjects:self, s, nil];
[s release];

将此项放入分配的第一个控制器的viewDidLoad方法中。

Put this in the viewDidLoad method of the first controller allocated.

或者你可以改变你的ApplicationDelegate设置TabBarController的方式,但我不会进入那个。

Alternatively you could just change the way your ApplicationDelegate sets up the TabBarController, but i won't go into that.

希望这有帮助

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

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