Tab bar icon and title not showing with Storyboard References
Asked Answered
S

9

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?

Shortridge answered 4/2, 2016 at 19:24 Comment(2)
I am also having same issue, you find any solution?Maciemaciel
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.Shortridge
S
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

Secunderabad answered 19/7, 2016 at 20:15 Comment(1)
Is there any way we can make the relationship by ourself?Sonar
G
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.

Gunnel answered 23/1, 2017 at 16:3 Comment(3)
Why does the tab bar disappear in the storyboard? Is it an Xcode bug?Lapillus
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.Gunnel
This solution is the quickest one. ThanksLavellelaven
B
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

Baguette answered 22/5, 2017 at 10:4 Comment(3)
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 stuffSot
You actually gave the same answer as @Driess stackoverflow.com/users/6216669/driesAlp
this solved the issue for me. Thanks a lotWycliffite
E
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

Errata answered 21/12, 2017 at 9:20 Comment(1)
This was what worked for me. Setting up these tab bar items is a little tedious because of the story board referenceSot
B
3

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

Bowerman answered 8/11, 2017 at 18:9 Comment(1)
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 referenceSurprint
A
3

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

Agamic answered 11/2, 2018 at 20:55 Comment(0)
B
1

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

enter image description here

this works for me

Botnick answered 23/11, 2022 at 23:28 Comment(0)
H
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

Hoopes answered 4/5, 2016 at 12:9 Comment(0)
E
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

Elwina answered 29/6, 2021 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.