jnpdx
jnpdx

Reputation: 52337

UITabBarItem title not displayed

I have a UITabBarController in which the first UITabBarItem title is not getting displayed. I have it set in Interface Builder and have tried to set it programmatically, but the title area stays blank.

[[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"Test1"];
[[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"Test2"];

UITabController view

(The Item 2 is set through Interface Builder, which is where that title is coming from, just to test that the IB titles are working as well -- except for the first one)

I have a feeling this is the odd result of adding the UITabController to the project and dragging the existing view into the first spot, but don't know how to fix it.

Here's the view in Interface Builder: enter image description here

Moving the ViewController that's in the first spot to the second spot yields the result you'd expect -- the second spot becomes blank and the first gets set with "Test1", meaning it's not something funny with just the first spot.

Upvotes: 2

Views: 2296

Answers (2)

Makis
Makis

Reputation: 41

Just go to your init method in your view controller's .m file and in order to set the tab bar item's title use:

[[self tabBarItem] setTitle:@"Main"];

and for setting its image, use:

[[self tabBarItem] setImage:[UIImage imageNamed:@"SomeFilename.png"]];

Upvotes: 4

Stian Storrvik
Stian Storrvik

Reputation: 2199

type [self setTitle:@"Title"] in your viewcontroller for the first view instead of declaring it through the viewcontrollers array. don't know whats wrong though, but I had to do this once

Upvotes: 3

Related Questions