Nothing shown at tab bar controller items when storyboard reference is added - ios

I have a tab bar controller and there are some view controllers attached to it. All of the view controller names and their corresponding items show up perfectly at the tab bar. The problem occurs when I try to add a Storyboard reference to it. Nothing is shown at the tab bar for that particular item(storyboard) when I run it. Although it shows up perfectly on the UI design.
[
Notice that the 3rd item (the storyboard reference) is invisible. Also, the invisible Storyboard reference works. Meaning, if I click on the invisible place it takes me to the proper storyboard.
I have seen some answers from here.
Refactoring to storyboard works. But I don't want to use it. Refactoring to storyboard creates a storyboard reference anyway. And it works perfectly. But when I create a storyboard reference, it doesn't work and stays blank.
Now, how should I add a storyboard reference to tab bar controller so that it shows up the name and the icon?

After the storyboard reference is correctly connected but the icon image doesn't appear, go to the initial view controller that is in the storyboard being referenced from the tab bar and make sure that the view of the initial view controller has a Tab Bar Item.
If it does, then add the desired image to the Tab Bar Item connected to the view. If the connected storyboard view does not have a Tab Bar Item, then add one and set the desired title and image. For other potential fixes this post is pretty good.

Related

show another storyboard as the content of 1st tab of TabBarController

I have a tab bar controller in storyboard like below:
I have anther storyboard which I would like to use as the content of 1st tab. Let's call it Content.storyboard
What I want to achieve is:
I would like the content of the 1st tab of Tab Bar Controller to be the Content.storyboard.
What I tried is:
I removed the default 1st view controller from Tab Bar Controller storyboard and added a storyboard reference connecting from Tab Bar Controller to Content.storyboard, like below:
The problem is , as you see above, I lost the ability to edit the Tab Item.
So, what is the correct way to achieve what I want? (That's showing a view from another storyboard as content of a tab of TabBarController)
I ran into an issue similar to this recently. I ended up moving the navigation controller out of the separate storyboard and into the main storyboard and configured the tab bar items there.
EDIT
After some further testing, it looks like the storyboard reference node gets a fake tab bar item. You can't delete it or modify it.
To provide the tab bar item for the other view controller, go into that storyboard and set the view controllers simulated metrics to Translucent tab bar:
Then you can drag in a tab bar item from the object library:
I chose the Bookmarks system icon. you won't see this reflected in the main storyboard, but you will at runtime (and on the child storyboard).
You can achieve this using container view
1) Take Container view in your tab
2) Delete added viewcontroller window (Usually come with container view )
3) Add storyboard Reference
4) Drag from container view to storyboard Reference choose embed option
I have also faced the same issue:
Follow the step:
Go to your Content.storyboard
Expand your initial view controller.
then -
After that:

Use Storyboard References While Retaining Icons & Text for Tab Bar Controller

I started refactoring one of my projects to make the code easier to manage and the Tab Bar Controller lost its icons for which tab represents what. Without this I'm a bit lost which tab is what for re-ordering purposes.
How do I get the icons to show up again for a tab bar controller when I'm using storyboard references?
Refer to my attached image. Notice how the first 3 tabs are 'blank' but the other tabs that I have not refactored yet show with the icons and titles.
For those unfamiliar with storyboard references I was following the tutorial here: http://code.tutsplus.com/tutorials/ios-9-staying-organized-with-storyboard-references--cms-24226
Sample of Tasks Storyboard to show Icon set Correctly
It seems another solution that worked for me without altering the Approach you went through:
Leave Storyboard references as it's
Go to Initial view controller in the referenced storyboard
Add Tab bar item to the scene
Configure it as you have done in UITabBarController storyboard
Clean & Run
Repeat it for all Storyboard references
Happy Coding!
First, in the storyboard where the tab bar controller is, there should be a scene for the referenced storyboard.
Just click on the scene that tab is associated with and click the tab bar at the bottom, then go to the attributes inspector, and you'll be able to assign a new icon to it.
Update - This approach no longer appears to work in Xcode 9.
Here's how to get the tab to show properly:
Put the first UIViewController that will be embedded in the tab in
the same storyboard as the UITabViewController.
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.
Select the content view controller.
Click the Editor menu and choose Refactor to Storyboard...
The UITabBarController tab will now point to the new storyboard
reference...
... and the content view controller preserves the UITabBarItem from
the tab bar relationship. It will appear normally in the app now.
For some weird reason, I wasn't able to see the tab bar in my reference view controller in IB. Although while selecting it and expanding the Document Outline, I was able to see it in my view list. I could make my changes through it.
Hope this helps! :)
XCode 11.1: The following approach gets the desired tab title and icon to show at runtime:
Create a storyboard reference to the desired storyboard (including the correct bundle identifier if it is located in an external framework).
Ctrl-drag from the tab bar controller to the reference you just created and select "Relationship Segue > view controllers" from the context menu that appears.
The tab bar should now show a square image with the title "Item" beside it. Click and drag this item to rearrange it in the bar as desired.
In the target view controller (which should be the first responder in the referenced storyboard), create a Tab Bar Item and set the Title and Image properties in the Bar Item section of the properties panel.
At this point, the correct title should appear at runtime (but not at compile time in the storyboard editor). If the icon is there too, great. If it's not, you can try checking that the image reference is valid and located in the same module as the tab bar item (i.e. in the same framework). If it still doesn't appear, here's a hackish workaround that will work:
Create a new class which inherits from UITabBarController.
Override viewWillLayoutSubviews as follows:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
// Set the tab bar image at runtime
if let exampleTab = tabBar.items?.first(where: { $0.title == "ExampleTitle" }) {
// To insert an image literal, type "Image" and select Image Literal
// from the autocomplete menu. An icon should appear.
// Double-click the icon and select the desired image from the grid.
exampleTab.image = Image Literal
}
}
Change the type of your tab bar controller to the subclass you created (from the Identity panel in the storyboard editor).
Finally, the tab bar item should now appear correctly at runtime. If anyone knows how to make it appear correctly at compile time too (in the storyboard editor) for a storyboard in an external framework, let me know.
If you embed a navigation controller before your scene, you then can edit it like normal.
Select your storyboard reference then:
Go to the top and click Editor > Embed > Navigation Controller
Tab bar controller with embedded navigation controller and linking storyboard reference

Navigation Item in XIB file is not visible

I'm in XCode 7.2.1 and I am trying to make a view that is reusable and should have some custom elements in the navigation bar.
If I would add a view to my storyboard, connect it via a segue to the navigation controller and make sure there is a "Navigation Item" in the view, I could see the navigation bar and edit my items in it.
If I manually add a Navigation Item to a XIB however I can't see anything. Even if I switch in the simulated metrics settings Top Bar to something else than Inferred or None.
I don't want to use the storyboard, if possible. Is there a descent way to make the navigation item visible and edit it?
Thanks in advance.
I don't think you link your View Controller correctly with Navigation Controller. When you link it, you should choose with root View Controller. If you link it correctly, you don't have to add NavigationItem manually.
By the way, you shouldn't do the customization for Navigation bar directly in xib. All you can do is only to set the Title, Prompt and Back Button text.
Do it in code! I think you won't have different styles for navigation bar in different views, right? That would be too silly.

Can't select tab bar items, greyed out tab bar

My nav bar is completely greyed out. I've seen some solutions like this saying that you should simply add an image to the tab bar item. I can't even select a tab bar item...see screen below.
Any ideas? I'm running Xcode 7.2, using Swift with a BaaS (Parse). I've searched for hours/days and can't figure this one out...May sound like a dumb question, but every other example I search essentially shows a tab bar with items that you can select/edit within the interface builder. As I can't figure out how to select a tab bar item within the interface builder, I've essentially been stuck. Do I need to do this all programmatically (I know some people have preference here), or can it be done in interface builder?
I add them as has been mentioned (using a view controller relationship segue, images below), but after I add it, everything is still greyed out and I don't have any tab bar items. Any ideas?
control-click action, using relationship segue under view controller
everything is greyed out, no tab bar items available to edit or add images to
Ok, here we go. You have a Tab Bar created.
Drag a View Controller to your storyboard. Place it next to your Tab Bar.
Ctrl-click on the Tab Bar and drag it to the View Controller.
Select the option like the image below.
About this this you must see the item on your tab bar. Click on it and you'll be able to edit (choose an image, change the label...).
Hope that helps.

How to add buttons to navigation controller visible after segueing?

I have set up a view controller in Storyboard which is embedded in a navigation controller. In this nav controller I have checked Shows Navigation Bar and Shows Toolbar and enabled a navigation bar and toolbar in Top Bar and Bottom Bar respectively in Simulated Metrics. I then "Show e.g. Push" segue from the view controller to another view controller. On both view controllers I've set up Simulated Metrics the same way, so both the navigation bar and toolbar are visible on all three controllers.
The problem is, I can add bar button items to the first view controller to both the navigation bar and the toolbar, but I cannot add a bar button item to the navigation bar on the second view controller. When I drop a button on the navigation bar, it's added to the toolbar instead. And I cannot double click the nav bar to add a title. In the outline I see there is no navigation item on the second view controller, but it is there in the first view controller.
I can probably add buttons to the navigation bar programmatically, but I want to do this visually in Storyboard. My question is, what is wrong with this setup, or is this a bug with Xcode?
For XCode 6, the UINavigationItem for the 2nd view controller onwards is not added automatically on the View Controller Object inside the storyboard. You will have to drag the UINavigationItem onto the Navigation Bar for that view Controller Object before adding UIBarButtonItem on top of it.
I am not sure why it is designed that way. I only discovered about this a few weeks ago.
If you have a ton of view controllers and very little custom auto-layout stuff in place, you can disable size classes, then re-enable it will add all missing nav bars across your storyboard.
Obviously not recommended if you have a ton of custom auto layout stuff linked up.
If you have just a single UIViewController that's missing a nav bar, just drop a UINavigationItem onto it.
If you're using Xcode 7 beta 4/5, try restarting Xcode it solved the issue for me
I just bumped into this issue and it seems to be affected by the segue that shows the view controller.
If "Kind" setting in segue is "Show (e.g. Push)", it's not possible to drag the item to top right corner. However, if you explicitly change "Kind" setting to "Push", this can be done.
Edit: actually I just noticed that "Push" is deprecated. Not sure what Apple is thinking here. However, you can just change it back to "Show" after adding the button and it seems to work :D
For second view controller in hierarchy, you can setup title in attributes, without adding "navigation item"
I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.
You can disable and enable the size classes in Interface builder doc.
It's very simple. You just need to use navigaitonItem first as the holder of the buttons and then you can add barButtonItems on top of that.

Resources