Having problems with combined tab bar and navigation bar controllers - ios

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.

Related

Navigating within Tab Controller

I am pretty new to Xcode and Swift (though plenty of experience with other languages) and am stuck on a rather trivial problem.
I set up a basic login/register page that goes into the main page of the app (a tab view controller) but I want there to be a unique navigation bar per tab. In the First Tab (Main View Controller) I want to be able to Log Out (go all the way back to the Login screen) as well as click the "+" which will show a new view controller. I had this all working before adding the Tab Controller.
Now that I have the Tab Controller, the Tab Controller is overriding the navigation bar section and I am stuck with the standard "< Back" button on the navigation bar. I have tried some tricks with hiding and showing navigation bars but no luck. My First Tab (Main View Controller) now only shows the "< Back" and not the Log Out and "+".
Furthermore, once the Log Out button is showing I need to get it to go all the way back to the login screen. I attached a picture to help.
XCode: 14.2
Swift: 5.7
Here's how I would setup the storyboard. Start by ignoring the need to login for a moment.
Make the tab bar controller the initial view controller of your storyboard.
Each tab of the tab bar controller should have its own navigation controller, if needed. In other words, a tab can either be a single view controller or it can be a stack of view controllers managed by a tab-specific navigation controller.
Now add the login controller as a controller that is presented modally over the tab bar controller.
On app startup you can immediately present the login controller over the tab bar controller if the user needs to login. Once the user successfully logs in you dismiss the login controller revealing the tab bar controller.
Later on when the user chooses to logout you present the login controller modally over the tab bar controller again.

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

How to segue to a specific view controller inside a tab bar controller with losing the tab bar?

Currently I have a tab bar controller that is connected to various navigation controllers like this:
I'm trying to navigate from one view controller to another view controller that is in a separate navigation controller. The only way I've been able to figure out how to keep the tab bar from disappearing is to create a modal segue to the original tab bar controller. The only problem doing this it automatically goes to the default tab bar viewcontroller and not the one I'm trying to reach.

add navigation bar, and tab bar to all pages

My current state of app is like this:
Current state of app
Navigation bar and tab bar are both images. There are buttons on the tab bar. Now I have the same set of buttons and images all across the app. I am a total noob in iOS. I wish to use some internal functioning like toolbar/navigation bar/tab bar which is provided by xcode itself, instead of using separate images. I want tab bar and navigation bars in all my pages. Is there any way to add these tab bars and navigation bars to all the pages?
I am also using a superclass, to inherit all the common functions.
I use swift.
You have to embed in your root view controller with anavigation controller, and that navigation controller embed in with a tab bar controller.
To "embed in" a view controller, just select your root view controller on thestoryboard and select Editor -> Embed in -> Navigation Controller.
To "embed in" your navigation controller, just select it on the storyboardand select Editor -> Embed in -> Tab Bar Controller

Tab Bar Controller is not in all UIViewControllers

I just created a tab bar controller in my project with 4 tabs in total.
It works fine between the 4 UIViewControllers.
However when I navigate to another UIViewController which is not one of the 4 tabs, the tab bar disappears.
I want it to be seen in every page. How can I do this?
Ok.
The way this is done is by using navigation controllers on each tab.
So, you have your tab bar controller. Then each tab has a navigation controller first and the root view controller of the navigation controller is the page you want in that tab.
Now when you use a push segue the navigation controller pushes the new page and the tab bar controller remains in place.

Resources