UITabBarController tabs and headers are not set until I touch them

I have set properties title

, image

and selected-image

each of my UIViewControllers in their method viewDidLoad:

. These view controllers are in the UITabBarController, and according to the documentation provided, if you set these three properties, the UITabBarController will automatically display them.

[self setTitle: @"title"];
[self.tabBarItem setImage: [UIImage imageNamed:@"image.png"]];
[self.tabBarItem setSelectedImage:[UIImage imageNamed:@"image-selected.png"]];


But the problem is that View controllers are not created until the user deletes the corresponding tab in the UITabBar, so no images or title are displayed until the tabs are clicked.

Is there a clean and OOP way to make the UITabBarController update and pull data from their view controllers? What's the point of having properties title

, image

and selected-image

if you need to manually specify which UITabBarController is?


source to share

2 answers


is not called until the view actually needs to be loaded the first time, which in this case when switching to the ViewController tab.

Try setting these properties in the initializer provided in the ViewController.



If you are using a storyboard you should use awakeFromNib instead. Like this:

- (void)awakeFromNib {
    [self setTitle:@"title"];
    [self.tabBarItem setImage:[UIImage imageNamed:@"image.png"]];
    [self.tabBarItem setSelectedImage:[UIImage imageNamed:@"image-selected.png"]];




All Articles