Swift Navigation Controller show on launch - ios

I create an app that can login, sign up and display list of users by using navigation controller and table view.
When user not logged in, then show the login page, otherwise show to list users page
But when app launching, the navigate controller always show first ether logged in or not. How can I hide that navigate on launching
Edit: initial controller is ViewController, navigation root view is the right one

For this I recommend you to take a different approach. Set your Users View Controller as the initial View Controller, and check if the user is logged in inside viewDidAppear. If they're not logged in, present the login page.

I don't know what happend, I just restart my mac and it run perfectly as expect

Related

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?

How to make a tabbar click show one of two viewControllers, depending if user is logged in?

Users can use the app without having to be logged in. However, if they go to the "profile" tab, of the tabbar, then:
1) if they are logged in, it shows them their profile.
2) if they are not logged in, it shows them a login page.
I can't figure out the best way to have this happen, because, I of course want to maintain the tabbar for both 1 and 2. If I segue with push or push detail from 1->2 or 2->1, the tabbar disappears.
You can subclass and write the UITabBarController. From that class you can set your tab bar view controllers. When setting the view controllers you can check whether the user is loggedIn or not. If user is loggedIn then you can set the view controller as Profile view else you can set the view as login view.
If user is going to login from that screen then you have to update the login view controller tab with profile view controller

How to skip a login view controller?

I develop an iOS app and my initial view controller shows a login form. Then when the user successfully authenticates the actual application is presented as a modal view controller.
When the user logs out the application it is dismissed and the login view controller is visible again.
My problem is:
When the application is started again and the user already is logged in I don't want to show the login view controller. I can't present the view controller before the login view controller is fully shown:
Warning: Attempt to present <UITabBarController: 0x10a271b40> on <LoginViewController: 0x10a2594f0> whose view is not in the window hierarchy!
I can present it with a delay but this is not what I want.
I could check if the user is logged in before I show a view (in the app delegate) and then show the login or the application. The problem with this is:
When the user logs out I have no login view controller beneath my application to which I can pop.
I can't find a good solution except defining the actual application as the root and present the login over it. But this brings a lot new problems because the main application needs data structures I can only initialize after login.
You don't want to be running with a modal always shown, it will be easy to inadvertently dismiss your 'entire app'.
Instead, do as you suggest in the app delegate where you decide which view controller is required and change the root view controller of the window. Again, when the user logs in / out, change the windows root view controller.
Most Application flow will be like that.
1) Set your tabbar controller as rootviewcontroller. When application launch, check with login status and show your tabbar(rootviewcontroller) if already logged in. Otherwise present modal view as loginview controller from tabbar(tabbar is rootviewcontroller).
2) When logout success, again show loginView as modal view(tabbar is rootviewcontroller).
Note: You can also shift rootviewcontroller as tabbar and loginview. But I recommented above flow.

What's the proper way to manage login state + login view (using storyboards)?

It's the first app that I'm creating that will use FB, Twtr and custom login.
I'll be using a dedicated login view/viewcontroller for this purpose.
My idea was to check the login state in the app delegate and go from there.
In case app delegate determines the user is not logged in
Set the login view as the root view controller
Login will display the rest of the app modally
If you log out, the modal view of the app is dismissed and you get back at the login screen
So in this case it looks perfect for me, but I can't figure the other case out:
In case app delegate determines the user is logged in
If you set the tabbar controller as the rootViewController there is no login view to dismiss to in case the user logs out..
I don't want the user to view the login screen if he is already logged in
A solution would be to invisibly set login vc as the root vc but immediately display the tab bar controller modally without the user noticing. I guess that's not possible?
You should always start with the Login screen at the root. The login views should be invisible and a UIActivityIndicator (or similar) should be shown while you determine if the user is logged in.
If the user is logged-in, simply push the next view controller and continue normally. If he isn't un-hide the login views.

Iphone application with login

I make iphone application. I use for root controller tab bar controller. One of my tabs is "My profile". In this tab I want to have two navigation view controllers. First controller should appear when user is not logged in. When user log in it should view second navigation controller. But I don't know how to do this. Can some one give some start point. Thanks.
You can use these links for your help.
Login Screen
screen switching

Resources