Combining single navigation controller with tab bar controller - ios

I want to combine a navigation controller and tab bar controller together and display 3 view controllers via the tab bar.
I can accomplish this if I embed each of the three vcs into its own navigation controller and then add those to the tab bar controller.
However there are now three navigation controllers.
But according to the Apple documentation, it is possible to use a single navigation controller: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html
To create a combined interface with three tabs that contain custom view controllers and one tab that contains a navigation controller:
1) Create three custom view controllers, one for each tab, and a navigation controller.
2) Select the three custom view controllers and the navigation controller (only the navigation controller scene, not it’s root view controller).
3) Choose Editor > Embed In > Tab Bar Controller.
4) Display the tab bar controller as the first view controller by selecting the option Is Initial View Controller in the Attributes inspector (or present the view controller in your user interface in another way.)
The first sentence in that quote mentions "a navigation controller", i.e. singular. And in the instructions it say "the navigation controller", also singular.
However when I follow these instructions I end up with a tab bar which contains 4 items, 3 for the view controllers and one for the navigation controller.
If its possible to have a single navigation controller as the Apple documentation says, what's wrong with the Apple instructions for doing so? How can I get three items in the tab bar?

The Apple document is just saying that you can use a navigation controller within a single tab to control navigation within that tab. If you have multiple tabs and want navigation controllers in all of them, then yes you can do that, but the three navigation controllers will be independent.
In other words, you can use both a tab bar and a navigation controller in your app, but not for the same purpose. The tab bar provides the top-level navigation, and the navigation controllers provide navigation lower down. You can't control your top-level navigation with both a tab bar and a navigation controller at the same time.
Here are the Apple Human Interface Guidelines regarding navigation.

Related

What's the best practices on UItabBars in navigationControllers?

I am creating an app using UItabBarController. I have 5 tabBar items at the bottom.
should I wrap navigationController in each item? Is that the best practice, and if not what's the best practice?
The tabs in a UITabBarController represent independent sections within an app. An example is Apple's Clock app. It has 4 tabs which are completely independent of each other.
A navigation controller represents a top-down hierarchy / stack of view controllers (meaning you start with a root view controller and then 'push' view controllers onto the stack. This almost inevitably means that it shows a 'logical flow'. You perform an action like selecting something on a view controller, which takes you into a more detailed view related to the action you performed. An example is Apple's Notes app which shows a list of folders of notes, selecting a folder pushes the screen with the list of notes in that folder onto the navigation stack, selecting a note in that list pushes the note that the user tapped on, onto the top of the list of notes.
Generally you should have tab bar controller as your app's root view controller and then each of the tabs could have a navigation controller as its root. It wouldn't usually have a tab-bar inside a navigation controller.
One case where a tab-bar could live inside a navigation controller is when a tabbed interface is presented modally.
To your question "should I wrap navigationController in each item", I think yes each tab should have a navigation controller as the root if a navigation hierarchy is required in that tab.
Hope this helps you.

Navigation Bar and navigation items not visible on runtime

I don't understand why SignIn and SignUp navigation Bar and the back buttons are not visible even when embedding both of these views in the navigation controllers.
Is there anything else we have to do in code. All top bars are inferred in this case and I haven't touched the visibility of any.
There is no back button because there is nowhere to go back to. Your sign up and sign in view controllers are the root view controllers of their respective navigation controllers.
There is no visible title because what you are looking at is the navigation item of the tab bar controller, which has no title.
Your architecture posits a navigation controller insider a navigation controller, which is illegal:
nav controller -> tab bar controller -> nav controller
You can't do that.
Also you can't put a tab bar controller inside a navigation controller. A navigation interface inside a tabbed interface is fine (as illustrate in Apple's own docs: https://developer.apple.com/documentation/uikit/uinavigationcontroller). The reverse, a tabbed interface inside a navigation interface, is not.
The simplest solution is to eliminate the first navigation controller completely, as there is no need for it (you are not pushing anything onto it beyond its root view controller).
IN SIMPLE TERMS
Logically, your Tabbar should not be embedded in a UINavigation Controller. Instead, delete the NavigationController and make the Tabbar the root Viewcontroller then embed each UIViewcontroller in a separate Navigation controller

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.

Having problems with combined tab bar and navigation bar controllers

I am having a problem with the back button not going to the previous view controller despite me using segues (via push). I think there is a problem since I saw this line on Apple's documentation saying
"An app that uses a tab bar controller can also use navigation controllers in one or more tabs. When combining these two types of view controller in the same user interface, the tab bar controller always acts as the wrapper for the navigation controllers."
But I want to be able to use a login screen which then moves onto a couple of screens before getting to a tab bar controller therefore not having the navigation bar wrapped in the tab bar controller. I know many popular apps use this, for example Instagram where you login then it shows the tab bar controller.
My current app layout is this;
Root navigation controller -> login -> meals (gif) -> tab controller (navigation controller for each tab (as per link) -> (My Rota/ My Meals/ Shopping List/ Item)
How to implement tab bar controller with navigation controller in right way
It looks like it is behaving as expected, the back button is for your root navigation controller and when you use the 'back' button it pops your tab bar controller. I actually expected you to see two navigation bars, your root one and the one in the My Meals tab, unless you hide one.
You could hide the root navigation bar when you push the tab bar, but you'll probably need a button in each tab's navigation bar which pops the tab bar from the root navigational controller.
Beyowulf's suggestion of presenting it as a modal is another option.

Create a TabBar Controller with a Master-detail template?

I created master-detail template for the ipad application and now I want to add Tab Bar to either master view or detail view. I can easily add tab bar controller using editor->embed in ->tab bar controller. However when I run application tab bar is not showing.
Tab bar is showing in storyboard but I am also unable to add extra tab bar items. What am I doing wrong thanks?
You should embed the navigation controller (of either the master or detail VC) in a tab bar controller, then delete the connection between the split view controller and that navigation controller. Finally, remake the connection from the split view controller to the tab bar controller. You'll also need to make several code changes, because the template code refers to the detail controller by its hierarchy in the split view controller, which will now be different.

Resources