swift xcode proper way to switch from navigation controller to tab bar controller - ios

I have embedded a navigation controller like this:
I have also set this to be my root view with the arrow in storyboard pointing to this. But now I want to change so my app use a tab bar instead of a navigation controller. I have tried to click on the navigation controller than add a tab bar controller. But when I search through my storyboard xml file I still see refrences to navigation controller

To replace the NavigationController with a TabBarController:
Select the NavigationController in the Storyboard.
Hit the delete key.
Select your ViewController.
Select Editor->Embed in->Tab Bar Controller from the menu.
Select the TabBarController and check Is Initial View Controller in the Attributes Inspector.

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.

Navigation controller back button doesnt appear?

I'm trying to setup back button on the navigation controller but it doesn't appear when I run it. I watched some tutorials and it usually works.
Your flow should be:
NavigationController --> MainVC --> FoodVC
Now you can add button as follow:
Navigation Item -> Left Bar Button Items -> Bar Button Item -> back button
Go to navigation controller scene -> navigation controller ->navigation bar - then go to right top show attributes option and change bar tint color.Try it
The view controller food is embedded in Navigation Controller , hence it is root view controller.
Navigation bar will appear when any viewController is push on same navigation controller.
So, If you tableview is already in Navigationcontroller then remove Navigation Controller in which Your FoodVC Controller is embedded.
If you want that navigation controller, you may add leftBarButtonItem programatically.
Totally depends on your requirement.
Is MenuVc your main Controller? try this, delete that navigation controller in the middle. Then click the MenuVc, embed in Navigation Controller and set the navigation controller as initial view controller at the attribute inspector. then navigate the menuVC to Food, "Show".

Tab Bar Item disappears after adding Navigation Controller

First I created a VC with TabBarController like this.
The other tabs and the main controller are at other storyboards.
Then, I added the Navigation Controller from the Editor > Embed In > Navigation Controller.
And the TabBarItem immediately disappears.
How can I change my tab bar icons and names?
In your storyboard you can change the tab icon from the Navigation controller. (Provided you have different navigation controllers for different tabs of your tab bar controller). YOUR NC will look something like this. (NC -> VC)
I checked your attach images. There are no issue with your navigation controller it will work fine with your tab bar.

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

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"..

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.

Resources