要本地化我的标签栏项目,我在 AppDelegate 中使用以下代码:
self.tabBarController = (UITabBarController*)self.window.rootViewController;
tabBarController.delegate = self;
tabBarController.selectedIndex = 0;
[[tabBarController.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"Home", nil)];
[[tabBarController.tabBar.items objectAtIndex:1] setTitle:NSLocalizedString(@"Requests", nil)];
[[tabBarController.tabBar.items objectAtIndex:2] setTitle:NSLocalizedString(@"Account", nil)];
[[tabBarController.tabBar.items objectAtIndex:3] setTitle:NSLocalizedString(@"Alarms", nil)];
[[tabBarController.tabBar.items objectAtIndex:4] setTitle:NSLocalizedString(@"Settings", nil)];
现在我添加了另一个项目并尝试添加一个新行,索引 = 5,但我得到一个“NSRangeException”,因为索引 5 超出了范围。 Xcode 自动添加了“更多”部分并将我的最后两项(设置和新项)移到那里。 我还看到用户现在可以自定义选项卡栏来选择项目顺序。 那么现在我怎样才能引用所有项目并将它们本地化呢? 注意:我正在使用 Storyboard。
谢谢。
最佳答案
对我来说最简单的解决方案是实现 awakeFromNib 方法,即使在使用标签时也会运行。
// Objective-C
- (void)awakeFromNib{
[super awakeFromNib];
self.title = NSLocalizedString(@"YOUR-LOCALISATION-TAG", @"");
}
// Swift
override func awakeFromNib() {
super.awakeFromNib()
self.title = NSLocalizedString("YOUR-LOCALISATION-TAG", comment: "")
}
关于ios - TabBar 项目本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12527161/