swift tab bar trying to show login view controller on certain pages - ios

I have just switched my applications navigation into tab bar.
Now I wonder how I can show a login VC when I click on certain tabs.
Before I just made a performSegueWithIdentifier() if the user was not logged in. But how can I do this with a navigation bar bar controller? I dont want the login VC to be displayed as an item in the navigation bar, I only want to show it if the user is not logged in and clicks on a certain tab item

You can have the tab bar controller's view controllers check whether the user is already logged in and if it is required -- present a login few controller if needed, say modally.

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.

Is it possible to present a view controller with a tab bar that has no icon selected?

My boss wants me to present a view controller when a tab bar is first presented. He wants the tab bar to have no icon or tab selected, with the user able to select a tab that then dismisses the view controller. Is this possible?
To my knowledge and research suggests that you must always have an icon selected when using a tab bar controller. Is that true?

Hide tabbar on one viewcontroller Xcode

I have a tabbed application in Xcode. I don't want my user to see the tab bar unless he logs in. My viewcontroller's name is Login
First present the login view controller which handles the input and validation of user credentials.
In case of success, present the tab bar controller either by replacing window root view controller (initially the login controller) or by pushing the tab bar controller on navigation stack (in this case the navigation controller is the initial view controller).

Show Login View Controller on Certain Pages of Tab Bar Application Swift

I have a tab bar application with three views. One of these requires the user to login to view the content.
I would like to initially show a login view when the user selects that tab and then after they are authenticated have them skip the login view and go directly to their content.
I've seen on other questions to check for authentication state in the ViewControllers viewWillAppear method and if not authenticated to present the login screen via a modal. However doing this hides the tab bar when showing the login view.
What would be the correct way to set this up?

login view controller and main tab bar controller

I have an app that should either show a login page or a main tab bar controller.
What's the best way to set this up? For now I'm starting out with an empty view controller and then either presenting a navigation controller for the login flow, or a tab bar controller for the main app. This means the entire contents of my app live within a modally presented view. Is that bad?
How do most people handle this?
I assume most people set the tab bar as their default view and present a modal login controller above it if necessary. Then when you log in you can just dismiss the login controller and you are back at your tab bar controller.
Your method should work just fine though.

Resources