I have a login view that uses Google Sign In. I have a navigation controller root set as the login view. When the user is logged in I want the navigation controller view to be set on the main page after the user is logged in. I tried making the main page after user is signed in to be the navigation controller, however, it needs to be set as the root controller which blocks out the login page. How would I go about this if I want to start the navigation controller at the main page view after user is logged in?
Asked
Active
Viewed 363 times
-3
-
For other people wondering how to solve this, I just had to add this line of code. `let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) let resultViewController = storyBoard.instantiateViewController(withIdentifier: "MapViewID") as! MapViewController self.navigationController?.pushViewController(resultViewController, animated: true)` – Connor Mar 23 '20 at 00:40
1 Answers
0
I think in your case what you want to do is to change the rootViewController with a new Different navigationViewController.
so what you do is pretty simple when you want to move from the "login view" to the "mainPageView" you need two things:
the appDelegate
to wrap main page view with a new navigationController
Now when you want to move to main page view simply instantiate its NavigationController and switch the rootViewController
here is an example:
if let navigation = UIStoryboard.init(name:"mainPageNavigation", bundle: Bundle.main).instantiateViewController(withIdentifier: "mainPageNavigation") as? mainPageNavigationController {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
appDelegate?.window?.rootViewController = navigation
appDelegate?.window?.makeKeyAndVisible()
}
and you are done:)

Mr Spring
- 533
- 8
- 17
-
Are you talking about like this? https://imgur.com/a/dk4y8qW Having two view controllers? And also where would I put that code at? – Connor Mar 22 '20 at 21:48
-
I suggest reading about ViewControllers and NavigationViewControllers. yes as the link describe when you want to move from loginView to MainPage you need to insert the code above with the navigation of "MainPage" identifier – Mr Spring Mar 22 '20 at 22:21