【发布时间】:2014-04-14 08:04:55
【问题描述】:
我正在尝试以编程方式更改我的应用中标签栏项目的名称。
在我的 storyboard 中,我将 UITabBarController 设置为初始视图,层次结构如下:
UITabBarController -> UINavigationController -> UITableViewController -> 详细视图控制器
要更改栏项目的标题,您需要更改 UINavigationController 的栏项目的标题。在 IB 中一切正常,但我需要本地化我的应用程序,这是我动态执行的(无需重新启动应用程序),每次启动应用程序时,IB 中给出的标题都已设置,并且标题不会更改为他们的本地化标题,直到我点击栏项目。
在我各自的 UITableViewControllers 中,我将标题设置为 self.title = localized title;,效果很好。 但我想让应用在启动时更改栏项目标题,直到我点击它们。
我已经查看了关于此问题的 SO 帖子并尝试了建议,但条形项目的标题仍然始终设置为 IB 中的值。我也在下面尝试了这段代码,但这只会在启动时设置选定的栏项:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Select the desired tab of our initial tab bar controller:
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
tabBar.selectedIndex = 1;
tabBar.navigationController.title = @"Item 2";
[(UITabBarItem*)[self->tabBarController.tabBar.items objectAtIndex:1] setTitle:@"Item 2"];
// Override point for customization after application launch.
return YES;
}
【问题讨论】:
标签: uitabbarcontroller tabbar items