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;
}
Bob Voorneveld
  • 553
  • 4
  • 10
  • 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. – CouchDeveloper Apr 29 '17 at 10:37
  • @CouchDeveloper 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. – User Aug 13 '17 at 14:11

4 Answers4

105

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

Interface Builder View of Destination Storyboard

leogdion
  • 2,332
  • 1
  • 19
  • 21
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.

  • 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](https://developer.apple.com/reference/uikit/uisplitviewcontroller). – CouchDeveloper Apr 29 '17 at 10:31
0

Refer following links

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

  2. Tab bar item not showing

Community
  • 1
  • 1
VRAwesome
  • 4,721
  • 5
  • 27
  • 52
-3

you can get storyboard reference like this

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

Divyanshu Sharma
  • 551
  • 2
  • 12