I'm trying to change the name of the tab bar item in my app programmatically.
In my storyboard I have a UITabBarController set as the initial view and the hierarchy is as follows:
UITabBarController -> UINavigationController -> UITableViewController -> Detail View Controller
To change the title of the bar item you need to change the bar item's title of the UINavigationController. In IB everything works well, but I need to localize my app, which I do dynamically (without app restart) and every time I start up the app the titles of the ones given in IB is set and the titles won't change to their localized title until I tap the bar item.
In my respective UITableViewControllers I set the title with self.title = localized title;
and that works well. But I want to have the app change the bar item titles at start up, and not until I tap them.
I've looked at posts here on SO regarding this issue and tried the suggestions, but still the titles of the bar items are always set to their values from IB. I also tried this code below, but that only sets the selected bar item at startup:
- (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;
}