在运行时重命名选项卡
我有一个选项卡栏应用程序,必须根据用户的偏好以不同的语言显示,但我找不到有关如何在运行时更改选项卡名称的太多信息。我需要选项卡在启动时显示正确的名称,而不是在访问选项卡时显示正确的名称。
我能找到的最好的信息是
self.tabBarController.selectedIndex = 1;
tabBarController.selectedViewController.tabBarItem.title = @"Tab Name";
从应用程序委托运行,但这首先使选项卡处于活动状态并打开该选项卡。然后设置名称。
是否有更好的方法在运行时设置选项卡名称?理想情况下,我想一次性将它们全部设置好。
I have a tab bar app that has to display in different languages depending on a user's preference but I can't find much info on how to change the tab names at run-time. I need the tabs to show the correct names at startup, not when the tabs are accessed.
Best info I could find was running
self.tabBarController.selectedIndex = 1;
tabBarController.selectedViewController.tabBarItem.title = @"Tab Name";
from the app delegate but this first makes the tab active & then sets the name.
Is there not a better way to set tab names at run-time? Ideally I'd like to set them all in one go.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您有对 UITabBar 的引用,则可以使用类似以下内容的内容:
If you have a reference to the UITabBar, you can use something like:
这两个答案对我来说不起作用,我最终这样做了:
The 2 responses didn't work for me, I eventually did it like this:
我建议您本地化您的 XIB 文件:
重复最后一步,直到获得所有请求的语言。
我更喜欢使用“en”而不是自动创建的默认“English” - 如果您也喜欢“en”,那么最后删除“English”...
现在您可以在每个区域设置的选项卡中输入不同的标题...
I suggest you to localize your XIB file:
Repeat the last step until you have all the requested languages.
I prefer to use "en" instead of the default "English" that is created automatically - if you prefer "en" too then delete the "English" in the end...
Now you can enter different titles to the tabs for each locale...
我这样做的方法是在应用程序委托中定义插座:
然后,在 IB 连接插座后,将其放入
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions :
它有效,但我对此也不满意 - 由于某种原因,我无法使可本地化的 MainWindow.xib 正常工作。
The way I did it is by defining outlets in the app delegate:
and then, after connecting the outlets at IB, puting this to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
:It works but I'm not happy with that either - for some reason I can't get a localizable MainWindow.xib properly working..
我正在使用:
I'm using: