1

In our AppDelegate application method we're accessing the root view controller:

let splitViewController = self.window!.rootViewController as! UISplitViewController
.... set variables on splitViewController

Then after successfully logging in we redirect to the root view controller:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "Home") as UIViewController
self.present(controller, animated: true, completion: nil)

But it seems that this login process is wiping out the variables that were set in step #a. Presumably as in step #b we're recreating the controller. How can we redirect without wiping out the variables set in #a?

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • That means you want to change the root view controller on login success? – LC 웃 Oct 31 '16 at 02:23
  • I just want to initialize the root view controller at start up. And then redirect to it after Login. – Marcus Leon Oct 31 '16 at 02:35
  • If its rootViewcontroller why do you need to redirect..Since you are accessing the splitViewController as rootViewController, i think its set in storyboard.App loads the splitViewController at startup.. – LC 웃 Oct 31 '16 at 02:41
  • At start up we redirect to a login controller if the user hasn't logged in. After Login we then redirect to root. – Marcus Leon Oct 31 '16 at 02:42
  • Don't do that...You need to set the loginViewController as the rootViewController and on login successful present the splitViewController. From next time,you check if use is logged in. If yes, you just present the splitViewController from Login may be in viewWillAppear method or from appdelegate making user unaware he just came through LoginVC. – LC 웃 Oct 31 '16 at 02:49

1 Answers1

0

We followed the approach of switching the root view controller when required. We launch the app and if user is not logged in we set the root to LoginViewController. After logging in we set the root back to UISplitViewController. The solution is from https://stackoverflow.com/a/25979945/47281

Community
  • 1
  • 1
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429