Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Switch between 2 Navigation controller

Tags:

In my app, if the user isn't logged, it shows a login controller which is embedded in a navigation controller. When the user is logged, the app should switch to the other navigation controller to display the app.

How can I switch from one navigation controller to another one when the user is logged. ?

Thanks

enter image description here

I'm checking if the user is log in app delegate :

 // Check if user is log     let currentUser = PFUser.currentUser()     if currentUser != nil {         // Do stuff with the user     } else {         // Show the signup or login screen         let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)         let nav = mainStoryboardIpad.instantiateViewControllerWithIdentifier("LogInController") as! UINavigationController         self.window?.rootViewController = nav     } 

SOLUTION : looks like it works
When user press logIn button :

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)     let nav = mainStoryboardIpad.instantiateViewControllerWithIdentifier("MainNavController") as! UINavigationController     let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate     appDelegate.window?.rootViewController = nav 
like image 703
user3722523 Avatar asked Nov 11 '15 22:11

user3722523


People also ask

How do I navigate from one screen to another in IOS?

You can control-drag from the cell in the table view to the view controller you want to link to allow the user to navigate to that screen when that cell it tapped.

What is use of UINavigationController?

A navigation controller is a container view that can manage the navigation of hierarchical contents. The navigation controller manages the current displaying screen using the navigation stack. Navigation stack can have “n” numbers of view controllers.

How do I segue to my navigation controller?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.


1 Answers

Solution 1

One solution would be to use just a single navigation controller. When the user logs in, you would pop all the view controllers used for logging in and push main view controller on the stack.

Solution 2

Alternatively, you could present a new navigation controller modally on top of the login stuff, with main controller as its root. It would be simply presented on top of it.

Solution 3

You can also consider creating the navigation controller with main view controller first and presenting the login navigation controller on top of it. Then, when user logs in you would just dismiss the login navigation controller revealing the main view controller.

like image 164
Rafa de King Avatar answered Sep 22 '22 18:09

Rafa de King