2

How do I change the UITabbaritem titles when starting the App?

I got a UITabBar with 4 tabs. I want the user to be able to change between two different languages. If the user chooses a different language I need to set a different title to the UITabbaritems. I know I can use self.title = @"title"; but that only changes the current tabbaritem title. How can I change all the titles at once, on load, and when choosing a different language?

CCDEV
  • 371
  • 1
  • 5
  • 16

2 Answers2

9

I got the same problem and solved it with.

[[self.tabBarController.viewControllers objectAtIndex:index] setTitle:@"Your title"];

Where index is your UITabBarItem index.

ppolak
  • 641
  • 5
  • 8
  • Works for me too. I wish this answer had a higher profile, I was searching for it for several hours!! – ICL1901 Mar 01 '12 at 18:22
0

You need to store all your UITabBarItem into an array, when the user tap the button, you need to loop through that array and set the title.

for (UITabBarItem *item in items) {
  item.title = @"WHATEVER HERE";
}
vodkhang
  • 18,639
  • 11
  • 76
  • 110
  • I think I understand where you are going with this. But can you be more specific? I tried to change the UITabBarItem of another view without getting a result. Where do I implement loop and do I need to change the title of the viewControllers or just the UITabBarItems? Thanks – CCDEV Jul 22 '10 at 18:16
  • In the buttonClicked: method that takes care of the event button is clicked, you put the loop. You can pass the array of UITabBarItem into the ViewController who holds the button – vodkhang Jul 23 '10 at 01:05
  • Thanks vodkhang, I will give it a go this weekend. – CCDEV Jul 23 '10 at 12:56