0
votes

I have a tab bar controller that has storyboard references linking the appropriate storyboard. I am having trouble localizing the tab bar titles. Currently the tab bar titles are set on the storyboard only. When I clear the titles for the tab bar items in the story board and attempt to set them in code below.

mainTabBar.items![0].title = NSLocalizedString("mainTabBar_tab0", comment: "")
mainTabBar.items![1].title = NSLocalizedString("mainTabBar_tab1", comment: "")
mainTabBar.items![2].title = NSLocalizedString("mainTabBar_tab2", comment: "")
mainTabBar.items![3].title = NSLocalizedString("mainTabBar_tab3", comment: "")
mainTabBar.items![4].title = NSLocalizedString("mainTabBar_tab4", comment: "")

This yields inconclusive results and the tab bar items remain blank.

Below is a screenshot of how I have my tab bar items established.

enter image description here

EDIT---Adding Localized Files

"mainTabBar_tab0" = "AA";
"mainTabBar_tab1" = "BB";
"mainTabBar_tab2" = "CC";
"mainTabBar_tab3" = "DD";
"mainTabBar_tab4" = "EE";

I am calling the tabBar items title code inside the main tab bar controller as shown in picture.

1
Could you post a snippet of your localized strings file? It's possible your keys aren't matching, so you get back empty strings. - kid_x
Also, where are you calling this code? - kid_x
Check update for your answers @kid_x - Julian Silvestri

1 Answers

1
votes

Could you try setting each ViewController title in their corresponding viewWillAppear? Something like this:

self.tabBarController?.tabBar.items?[0].title = NSLocalizedString("mainTabBar_tab0", comment: "comment")

Hope it helps