20

I have the following storyboard with a segue to a storyboard reference:

enter image description here

The problem is that when I run the app, it doesn't show the icon or the title:

enter image description here

These are the item settings:

enter image description here

What am I missing?

Brian
  • 14,610
  • 7
  • 35
  • 43
MVZ
  • 2,220
  • 5
  • 27
  • 57
  • 2
    I am also having same issue, you find any solution? – Vibhooti Jun 09 '16 at 13:06
  • Somebody just posted an answer bellow. I'm not on this project anymore so please let me know if it works and I'll mark it as an answer. – MVZ Jul 20 '16 at 17:19

9 Answers9

19

Here's how to get the tab to show properly:

  1. Put the first UIViewController that will be embedded in the tab in the same storyboard as the UITabViewController. enter image description here
  2. Ctrl + Drag from the tab bar controller to the content view controller to make the connection as per usual. This will automatically add the UITabBarItem to the bottom of the content view controller. enter image description here
  3. Select the content view controller.
  4. Click the Editor menu and choose Refactor to Storyboard... enter image description here

The UITabBarController tab will now point to the new storyboard reference... enter image description here ... and the content view controller preserves the UITabBarItem from the tab bar relationship. It will appear normally in the app now. enter image description here

Drew C
  • 6,408
  • 3
  • 39
  • 50
18

You can modify image/title of the tab bar item in the initial view controller of the storyboard you are referring to. You just need to add a 'tab bar item' to the initial view controller and change its properties (title/image) accordingly.

  1. Outline view of the root view controller in the referred storyboard

document outline of referred to storyboard

  1. The modified tab bar item in the view controller

initial view controller with modified tab bar item

Note: the change will not be reflected on the tab bar in the main storyboard; you only see it in the referred storyboard and at runtime.

shim
  • 9,289
  • 12
  • 69
  • 108
Dries
  • 385
  • 3
  • 12
  • Why does the tab bar disappear in the storyboard? Is it an Xcode bug? – Cons Bulaquena Mar 03 '18 at 03:33
  • I think it has to do with the fact that it is a different file (Storyboard) and Xcode doesn't implement it (reading the entry view controller from a referenced story-board). So more a feature lacking than an actual bug I would think. – Dries Mar 03 '18 at 03:43
  • This solution is the quickest one. Thanks – carmine Mar 07 '18 at 09:59
16

The problem is that in the target view controller, you don't have a UITabBarItem in the views hierarchy. The TabBarItem is related to the storyboard reference, but should be related to the View Controller.

Looks like a "bug" in Xcode...

To resolve this you can do the following:

  • Just create the segues from the UITabBarController to the Storyboard references.
  • You may configure the Tab Bar Items in the storyboard references, they don't do much more other than showing the tabs in the tab bar on the Storyboard, which is nice for development purposes.

If you now run the app, you will indeed notice that the tabs are missing. To get the tabs to display in the running app as well, do this:

  • Go to the viewcontroller the storyboard reference is referencing to
  • Add a Tab Bar Item into this View Controller by dragging it from the Object Library into the View Controller
  • You will now see a tab bar with one single tab in the view controller
  • Configure the tab bar item to show the correct title and icon

Now run the app and you will now see your tabs.

In interface builder, find the Tab Bar item in the Object Library

Drag the Tab Bar item into your the destination view controller by following the storyboard reference

Bocaxica
  • 3,911
  • 3
  • 37
  • 54
  • 1
    This solved my problem. Even though I did not need to add bar items to other ViewControllers that are also displayed in the same UITabBarController. I only needed to do this with one of the view controllers for it to display. Weird stuff – jcpennypincher Jun 14 '18 at 18:15
  • You actually gave the same answer as @Driess https://stackoverflow.com/users/6216669/dries – AndaluZ Jul 02 '19 at 14:37
  • this solved the issue for me. Thanks a lot – CocodyRockStar Dec 03 '20 at 22:10
6

I tried adding another tab bar, then added tab bar item, selected and image for it BUT Non of above seemed to work with my case .. it was like this : Other VC tabs were showing tabBar icons properly but one that i refactored was missing its icon

Then i compared it with VC that were working properly with TabBar icons.. enter image description here

later i found that my navigation items and tab bar items were not together :

The Tab bar item was inside with Navigation Bar.... i dragged the tabBar item to HomeVC and placed with NavigationBar item

Now its working :):)

enter image description here

Parajuli Roman
  • 551
  • 1
  • 6
  • 15
4

After struggling with this problem for a few days I found this solution. Double click the storyboard link, which will open the referenced storyboard. In the scene navigator, you can edit the bar item with a custom title and icon. Works in xCode 9.

Storyboard

Scene Navigator

QuattroDog
  • 41
  • 3
  • Adding the bar item by directly opening the storyboard that is referenced/has the initial VC will not work. Follow steps above such as if you want to open the initial VC of the tab, open it by clicking the storyboard reference – naz Dec 17 '18 at 11:53
2

I had this exact same issue and neither of the above answers worked in my case. I solved by setting my tab bar image in the image bar item section inside the storyboard's reference like shown in the attached image:


enter image description here

Mauricio Chirino
  • 1,182
  • 17
  • 19
1

Just add a Tab Bar Item in the "child" view controller:

enter image description here

this works for me

Carlos Minero
  • 51
  • 1
  • 6
0

I made following in the storyboard and made class for each UINavigationController and made following code in each UINavigationController class

override func viewDidLoad() {
        super.viewDidLoad()
        let someController = StoryboardManager.surveyStoryboard.instantiateViewControllerWithIdentifier("SomeController") as! SomeController
        viewControllers = [someController]
        // Do any additional setup after loading the view.
    }

enter image description here

Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115
0

I did it in different way. My fourth tab was not showing. I just programmatically placed image on its place. You need to set its X,Y coordinates accordingly.

    let imageName = "video"
    let image = UIImage(named: imageName)
    let imageView = UIImageView(image: image!)
    imageView.frame = CGRect(x: view.frame.width - 80, y:  view.frame.height-70, width: 50, height: 50)
    view.addSubview(imageView)

enter image description here

Clean Coder
  • 496
  • 5
  • 12