UItabbar item not showing storyboard reference
Asked Answered
P

4

34

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;
}
Phony answered 17/11, 2015 at 10:15 Comment(2)
As of Xcode 8.3.x this is still the observed behaviour. I consider this a bug, since I believe that the storyboard reference was actually meant to provide the TabBar Item. It sill seems, the workaround as described by @leogdion is the way to go currently.Isiahisiahi
@Isiahisiahi have you (or anyone else) tested this in Xcode 9? It also looks to me definitely like a bug. It should be possible to set this using the reference.Twin
T
105

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

Interface Builder View of Destination Storyboard

Tacy answered 17/11, 2015 at 14:52 Comment(4)
This is the correct solution to this issue. Thank you for your answer.Dawnedawson
Just like UINavigationItems (sometimes). Thanks for the answer.Bathometer
This worked - to be more clear, you drag a Tab Bar Item from the object library on to the view-controllerGail
tabbarItem is showing, but I still can't modify it programmlyLoriannlorianna
O
6

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.

Orcus answered 20/4, 2017 at 12:29 Comment(1)
Thanks for this info, however your issue may also stem from the fact that : "Split view controllers are normally installed at the root of your app’s window. ", as described in the official docs.Isiahisiahi
U
0

Refer following links

  1. How to change the tab bar image color for selected and unselected

  2. Tab bar item not showing

Unfledged answered 17/11, 2015 at 10:58 Comment(0)
C
-3

you can get storyboard reference like this

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

Cole answered 17/11, 2015 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.