In swift: how to add tab bar icons to a regular ViewController storyboard? - ios

I would like to add two tab bar icons (table view and collection view), as shown in the first figure below, to a regular ViewController storyboard (as shown in the second figure).
I have tried to embed the ViewController in the TabBarController (Editor -> Embed in -> Tab Bar Controller), but it seems to me that xcode only allows me to add one icon (Tab Bar Item).

You need one view controller per tab in the storyboard, then connect the tab view controller to those controllers using "relationship segue", "view controllers" (ctrl-drag from tab view controller to destination controllers, then select that).
In each controller you then can click the tab item and set an image, in attributes.

add tab bar item to the view controller u want to add in tab bar controller. and then control drag from tab bar view controller and the make "relationship segue as "view controllers"..

Related

How to change the view in one tab of an UITabBar? [duplicate]

I am using Storyboard and Xcode 6. I have next controllers and scenes in my Storyboard:
UINavigationController that has HomeViewController as a root. HomeViewController has a button that Show (e.g. Push) UITabBarController. UITabBarController has 4 UIViewControllers.
But my problem that after I Show UITabBarController there are no Navigation Bars in 4 UIViewControllers. But I supposed that if I Show (e.g. Push) UITabBarController then it should has embedded navigation controller that is initial controller in storyboard. Am I right? And if so how can I setup then navigation bar in Storyboard, because there are now default bar event in pushed tab bar that I see on storyboard. I have selected UIViewController and set simulated metrics in identity inspector to Translucent Navigation bar for the Top property, but I supposed it should be automatically added to this controller and to the tab bar without additional steps.
Or should I add new navigation controller for each tab bar items that will have their root view controllers?
The main question why I don't see navigation bar in storyboard using show (e.g. Push). For example if I add navigation controller and then set as root - tab bar controller then Xcode automatically add top navigation bar, but if the queue has an extra step like in my case HomeViewController the top navigation bar never appear automatically.
Hi you need to embed each view controller that is within the tab bar in a navigation controller of its own. So the flow is like so (HomeVC is embedded in a NavController of it's own):
/ --> `NavController` --> `ViewController1`
| --> `NavController` --> `ViewController2`
`HomeViewController`-->`TabBarController`|--> `NavController` --> `ViewController3`
\--> `NavController` --> `ViewController4`
Go to Editor --> Embed In --> Tab Bar Controller (or Navigation Controller)
To answer your questions:
Each tab of a tab bar controller interface is associated with a custom (different [sic]) view controller. When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views.
So the Root View Controller of the tab must be adjoined to a Navigation Controller; a navigation view controller must be next inline in order for the View Controller to inherit a Navigation. A Tab Bar switches views to whatever is next inline.
This document will help outline more information about it. https://developer.apple.com/documentation/uikit/uitabbarcontroller
In Swift 2, Xcode 7 has a very handy feature for adding a UINavigationController:
Select the UIViewController that is being used as a "tab" for the UITabBarNavigationController
On the top Xcode menu, select "Editor" ->
"Embed In" ->
"Navigation Controller"
If you want to have something like that:
TabBarController -> Navigation Controller -> View Controller with a Table View -> and from the TableView a MasterDetailView for example:
I had the problem that there were no Navigation in the MasterDetailView (no Back Button to the ViewController with The TableView).
Workaround is:
Set Segue between TableView and MasterDetailView to:
Kind: Push (Deprecated)
Run your app...hopefully you will see the Back Button...change the Kind to Show (e.g. Push), run again -> it should work.

Add Tab Bar to Navigation Controller

I want to add a tab bar with three options (Home) the first view, (Incidences) with the second view, and (Info) with the third view, in the first view I have 2 buttons that shows the second and the third view.
What I have to do to add tab bar with these 3 tabs, always visible in the App?
I have this structure now:
New project -> Tabbed Application.
Replace the First and Second Views with your viewControllers. There will be no need for your left hand side view as the tabs will be your buttons
Each UIViewController in UITabBarController could be embedded in an UINavigationController at your convenience, that way you'll be able to use all of the features that you need.
Apple guideline for Tabbar: Tab Bar Controllers
Basically, you need to select the View Controller of (associated with) Tab Controller ▶ click on Editor menu item ▶ select Embed in and click on Navigation Controller
For correct flow of navigation using tabbar you need to bind tabbar
controller with View Controller first and then embed navigation
controller to tabbar. Similar way you can also embed navigation
controller to tabbar controller, but its not the correct flow.

Swift-How do I add Tab Bar AND Navigation Bar to a single view controller?

Using XCode, and either through Code or through the Storyboard, can someone please explain to me how to add both a Tab Bar and Nav Bar to my view controller while keeping both visible?
Thanks so much.
In your Storyboard, you should drag out a Tab Bar Controller and use that as the initial view controller. Then, you should embed each of the view controllers attached to the Tab Bar Controller inside Navigation Controllers (Editor menu: Embed In > Navigation Controller). Afterward, your Storyboard should look something like this:
The tab bar controller holds a tab bar and will manage switching between the other views attached to it, while the navigation controllers will place Navigation Bars at the top of each tab and help you manage navigation within the tab.
I am assuming you want something like this. Here is how I did it in Interface Builder:
Click your view controller.
Editor -> Embed In -> Navigation Controller
Reselect your view controller.
Editor -> Embed In -> Tab Bar Controller
Select the Navigation Controller
Check the box next to Is Initial View Controller
Hope this helps!

How to implement tab bar controller with navigation controller in right way

I am using Storyboard and Xcode 6. I have next controllers and scenes in my Storyboard:
UINavigationController that has HomeViewController as a root. HomeViewController has a button that Show (e.g. Push) UITabBarController. UITabBarController has 4 UIViewControllers.
But my problem that after I Show UITabBarController there are no Navigation Bars in 4 UIViewControllers. But I supposed that if I Show (e.g. Push) UITabBarController then it should has embedded navigation controller that is initial controller in storyboard. Am I right? And if so how can I setup then navigation bar in Storyboard, because there are now default bar event in pushed tab bar that I see on storyboard. I have selected UIViewController and set simulated metrics in identity inspector to Translucent Navigation bar for the Top property, but I supposed it should be automatically added to this controller and to the tab bar without additional steps.
Or should I add new navigation controller for each tab bar items that will have their root view controllers?
The main question why I don't see navigation bar in storyboard using show (e.g. Push). For example if I add navigation controller and then set as root - tab bar controller then Xcode automatically add top navigation bar, but if the queue has an extra step like in my case HomeViewController the top navigation bar never appear automatically.
Hi you need to embed each view controller that is within the tab bar in a navigation controller of its own. So the flow is like so (HomeVC is embedded in a NavController of it's own):
/ --> `NavController` --> `ViewController1`
| --> `NavController` --> `ViewController2`
`HomeViewController`-->`TabBarController`|--> `NavController` --> `ViewController3`
\--> `NavController` --> `ViewController4`
Go to Editor --> Embed In --> Tab Bar Controller (or Navigation Controller)
To answer your questions:
Each tab of a tab bar controller interface is associated with a custom (different [sic]) view controller. When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views.
So the Root View Controller of the tab must be adjoined to a Navigation Controller; a navigation view controller must be next inline in order for the View Controller to inherit a Navigation. A Tab Bar switches views to whatever is next inline.
This document will help outline more information about it. https://developer.apple.com/documentation/uikit/uitabbarcontroller
In Swift 2, Xcode 7 has a very handy feature for adding a UINavigationController:
Select the UIViewController that is being used as a "tab" for the UITabBarNavigationController
On the top Xcode menu, select "Editor" ->
"Embed In" ->
"Navigation Controller"
If you want to have something like that:
TabBarController -> Navigation Controller -> View Controller with a Table View -> and from the TableView a MasterDetailView for example:
I had the problem that there were no Navigation in the MasterDetailView (no Back Button to the ViewController with The TableView).
Workaround is:
Set Segue between TableView and MasterDetailView to:
Kind: Push (Deprecated)
Run your app...hopefully you will see the Back Button...change the Kind to Show (e.g. Push), run again -> it should work.

Adding new tabs to a tab bar controller

I am creating a tab bar iOS app. The tab bar view controller has two tabs, each of them connected to a view controller.
This how it looks:
I need to add more tabs to the tab controller. I am doing it at the storyboard as follows:
I add a new view controller.
I control-drag from the tab bar controller to the new created view controller.
A window opens and I select Relationship Segue-View Controller.
The segue from the tab bar controller to the new view controller is created.
I think that is the way to do it, but after that the tab bar controller doesn't show any tab icons, the tab bar becomes grey.
Like this:
I need to know what am I doing wrong.
First drag A TabBarController from Object Library you see that only two tabs with thier VC there.
to add more Tab Item in TabBarVC drag VC from Object Library
Then Control drag from TabBarVC to Newly VC then Segue relation pop ups
Select last one Relationship Segue -> View Controllers
I had the same problem until I added a tab bar item from the object library into the new view (settings its attributes on the right hand panel) and THEN ctrl dragged from the tab bar controller to the new view, creating a relationship segue.
If I tried to ctrl drag from the tab controller without first adding a tab item to the new view, it had the behaviour you described.
be sure to check the size of your icon image.
the tint of image added is grey by default. If you have a large sized tab bar image, it can look like the whole tab bar is greyed out for some reason. pic does not auto resize.
bellow process is follow in Xcode 9.4 for adding new item in tab bar controller.
1)Drag and Drop new Tab Bar Controller into sotrtyboard
2)It will show 2 item which connected with 2 view controller.
3)For adding third item button in tab bar controller
i) Add new View Controller.
ii) Right click on Tab Bar Controller and Drag into new view controller.
iii) one option popup will display inside that popup select "view controllers" options
It will create relationship link and will generate automatic item button in tab bar controller.
need to add/drag icon (from showing the media library) to the 3rd view controller, so that it can display properly.
Restarting Xcode 6.1.1 solved the issue for me while I was working on multiple projects.
go t0 library and choose tabbar controller then drag and drop after that take another uiviewcontroller and then click on tabbar and control and right click then drag and drop in the uiviewcontroller then you see some options where you have to choose in the relationship segue -> view controller
for more clearance see these images

Resources