本文介绍了标签栏项目标题出现在情节提要之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从一个带有5个标签的标签栏控制器开始.刚开始时,第一个带有名称,但是其他四个直到我单击它们时才有名称.然后,根据用户使用的语言显示名称.如何在标签栏出现之前设置标签名称?我正在使用情节提要.当其余所有操作都通过情节提要完成时,是否可以通过程序在选项卡栏上设置标题?我在AppDelegate中尝试了类似 [FirstViewController setTitle:NSLocalizedString(@"Titel1",nil)]; 但是我收到一个错误,即选择器setTitle没有类方法.谢谢.

my app starts with a tab bar controller which have 5 tabs. At start the first one in presented with its name but the other four don't have a name until I click on them. Then the name appears depending which language the user has.How can I set the name of the tabs before the tab bar appears?I am using storyboard. Is there a way to set title at the tab bar programmatically when all the rest is done with storyboard? I tried in the AppDelegate something like [FirstViewController setTitle:NSLocalizedString(@"Titel1", nil)];But I got an error that there is no class method for selector setTitle.Thanks.

推荐答案

我今天遇到了同样的问题.我也在使用情节提要.就我而言,我采用以下方式.

I had the same problem today. I'm using storyboard too. In my case i used the following way.

  1. 我创建了一个新的"Objective-C类",名称为"MainTabBarViewController"作为"UITabBarController"的子类.
  2. 在身份检查器"的情节提要中,我将自定义类"更改为"MainTabBarViewController".

  1. I've created a new "Objective-C class" with the name"MainTabBarViewController" as a subclass of "UITabBarController".
  2. In my storyboard in "identity inspector" i changed "Custom class" to "MainTabBarViewController".

在"MainTabBarViewController"的"viewDidLoad"方法中,我添加了:

In the method "viewDidLoad" in "MainTabBarViewController" i added:

[[[self.viewControllers objectAtIndex:0] setTitle:NSLocalizedString(@"home",nil)];

[[self.viewControllers objectAtIndex:0] setTitle:NSLocalizedString(@"home", nil)];

[[[self.viewControllers objectAtIndex:1] setTitle:NSLocalizedString(@"statistics",nil)];

[[self.viewControllers objectAtIndex:1] setTitle:NSLocalizedString(@"statistics", nil)];

[[[self.viewControllers objectAtIndex:2] setTitle:NSLocalizedString(@"settings",nil)];

[[self.viewControllers objectAtIndex:2] setTitle:NSLocalizedString(@"settings", nil)];

[[[self.viewControllers objectAtIndex:3] setTitle:NSLocalizedString(@"info",nil)];

[[self.viewControllers objectAtIndex:3] setTitle:NSLocalizedString(@"info", nil)];

我想这不是完美的方式,但对我来说,它是完美的.

I guess it is not the perferct way, but for me it works perfect.

这篇关于标签栏项目标题出现在情节提要之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 06:44