Bob Voorneveld
Bob Voorneveld

Reputation: 553

UItabbar item not showing storyboard reference

I'm trying to use the new storyboard references in a tabbar. When I use the storyboard reference, the UITabBarItem (with customized image & text set), isn't showing anything. See setup: storyboard setup

tabbaritem setup

I fixed it for now by setting the images & title in the initWithCoder function for the initial viewcontroller in the referenced storyboards like so:

static NSString *const ContactsViewControllerTabContactImageName = @"tab-contact";
static NSString *const ContactsViewControllerTabContactActiveImageName = @"tab-contact-active";

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.title = NSLocalizedString(@"Contacts", nil);
        self.tabBarItem.image = [UIImage imageNamed:ContactsViewControllerTabContactImageName];
        self.tabBarItem.selectedImage = [UIImage imageNamed:ContactsViewControllerTabContactActiveImageName];
    }
    return self;
}

Upvotes: 34

Views: 8254

Answers (4)

user1199624
user1199624

Reputation:

This answer is pretty late, but I had an similar problem. This may be helpful for others who find this post later.

When using a UISplitViewController there is an issue for me adding the item in storyboard which can be solved with a workaround.

Scenario:

UITabBarController -> StoryboardReference -> UISplitViewController

Problem:

You can't add an UITabBarItem to the UISplitViewController

Solution / Workaround:

Add an UITabBarController within the UISplitViewControllers storyboard and assign the UISplitViewController as one of the tabs.An UITabBarItem will be added to the UISplitViewController. You can delete the unnecessary UITabBarController. The UITabBarItem will be kept.

Upvotes: 6

leogdion
leogdion

Reputation: 2350

You need to add the tab bar item in the destination storyboard view controller.

Interface Builder View of Destination Storyboard

Upvotes: 105

Divyanshu Sharma
Divyanshu Sharma

Reputation: 561

you can get storyboard reference like this

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];

Upvotes: -3

Related Questions