my app starts with a tab bar controller which have 5 tabs. At start the first one in presented with its name but the other four don't have a name until I click on them. Then the name appears depending which language the user has.
How can I set the name of the tabs before the tab bar appears?
I am using storyboard. Is there a way to set title at the tab bar programmatically when all the rest is done with storyboard? I tried in the AppDelegate something like [FirstViewController setTitle:NSLocalizedString(@"Titel1", nil)];
But I got an error that there is no class method for selector setTitle.
Thanks.

- 573
- 1
- 11
- 23
5 Answers
I had the same problem today. I'm using storyboard too. In my case i used the following way.
- I've created a new "Objective-C class" with the name "MainTabBarViewController" as a subclass of "UITabBarController".
In my storyboard in "identity inspector" i changed "Custom class" to "MainTabBarViewController".
In the method "viewDidLoad" in "MainTabBarViewController" i added:
[[self.viewControllers objectAtIndex:0] setTitle:NSLocalizedString(@"home", nil)];
[[self.viewControllers objectAtIndex:1] setTitle:NSLocalizedString(@"statistics", nil)];
[[self.viewControllers objectAtIndex:2] setTitle:NSLocalizedString(@"settings", nil)];
[[self.viewControllers objectAtIndex:3] setTitle:NSLocalizedString(@"info", nil)];
I guess it is not the perferct way, but for me it works perfect.

- 357
- 1
- 11
-
I can't believe it!! I've been looking for this solution for so long. Thank you so much :) – thedp Oct 14 '13 at 00:36
-
See my solution below, it doesn't require setting titles with indices. – Markus Rautopuro Mar 23 '14 at 17:29
-
Thank you for the answer. It works for updating the UITabBarItem images too. – Eneko Alonso Jan 18 '16 at 01:17
I had a configuration with two tabs like this:
MainTabBarController : UITabBarController
+- MessagesNavigationController : UINavigationController
+- ContactsNavigationController : UINavigationController
In a configuration with Storyboard and ARC I overrode the initWithCoder:
selector in the custom classes of my UITabBarController view controllers (in this case ContactsNavigationController
) and initialized the tabBarItem.title
there like this:
@implementation ContactsNavigationController
...
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
self.tabBarItem.title = NSLocalizedString(@"Contacts", nil);
}
return self;
}
When using storyboards the iOS calls (id)initWithCoder:
instead of -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
when the storyboard view controller is initialized during UITabBarController launch. Also note that viewDidLoad
doesn't get called until the view controller tab is selected from the tab bar.

- 7,997
- 6
- 47
- 60
In the app delegate, where you are creating the view controllers, set the title property here (rather than in viewDidLoad
), for example:
vc1 = [[VC1 alloc] init];
vc1.title = @"List";
vc2 = [[VC2 alloc] init];
vc2.title = @"Map";
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];

- 2,143
- 16
- 18
-
I am using storyboard. So I created them in storyboard. Is there another way to do this in storyboard? – halloway4b Apr 10 '12 at 12:43
-
If you take a look at the FirstViewController created by Xcode using the template Tab-Bar application based in the - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
method you can see something like this:
if (self) {
//check your language
self.title = NSLocalizedString(@"First", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
So you have to check for your language and then set the title
property, this will set the title on the tab bar and in the navigation bar.
-
I have a Tab Bar View Controller in Storyboard and when it is presented I want all tab bar title to be shown depending which language the user has configured in his iPhone. – halloway4b Apr 10 '12 at 13:46
Try this, in every view u have to use this method
Suppose this is you first view
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"homepage", @"homepage");
[self.tabBarItem setTag:0];
self.tabBarItem.image = [UIImage imageNamed:@"homepage"];
}
return self;
}
In you app delegate class write this code to add UITabBarController
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,viewController4,viewController5, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Add above code in
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {}

- 7,220
- 17
- 76
- 135

- 1,658
- 1
- 16
- 37
-
i don't know about the story bored but it will defiantly work in other projects – freelancer Apr 10 '12 at 13:13