0

In my app, I start with a login flow and after login is done, it will navigate into the Dashboard. I am trying to reset the navigation stack so that when I am in Dashboard, I don't get to go back to the login screens. I might be able to achieve this by hiding the back button in Dashboard but I believe resetting the stack is a more appropriate way but how do I do this?

Samuel Kith
  • 109
  • 12

1 Answers1

0

change root view controller to a new UINavigationController.

If your have to check if the user is already logged in, do this in AppDelegate after finding session of login:

self.window?.rootViewController = UINavigationController(rootViewController: dashboardVC)

If you want to navigate to dashboard after login success:

let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = UINavigationController(rootViewController: dashboardVC)

This code starts your viewController from a new navigation stack where DashboardViewController is the root viewController of the stack.

Mukesh Shakya
  • 425
  • 3
  • 9
  • Correct me if I am wrong, I am not trying to reset the rootViewController, when the app launches, it still should go through the login flow. By resetting the window rootViewController, when the app launches, it will start with the Dashboard right ? – Samuel Kith Jun 05 '19 at 09:53
  • It does not start with the Dashboard after the relaunch of app since your app Main interface is unchanged. – Mukesh Shakya Jun 05 '19 at 09:56
  • When should I set this, in Dashboard or Login ? – Samuel Kith Jun 05 '19 at 10:06
  • 2nd approach if you want to do it after login success in Login. – Mukesh Shakya Jun 05 '19 at 10:08
  • Are they two different approaches? I can't seem to set self.window? in my ViewController. – Samuel Kith Jun 05 '19 at 10:10
  • If your have to check if the user is already logged in, do this in AppDelegate after finding session of login do the 1st approach otherwise 2nd approach from the view controller. – Mukesh Shakya Jun 05 '19 at 10:11
  • Thank you, got it worked. To do it with animation, refer to https://stackoverflow.com/a/29861928/11315473 and https://gist.github.com/nvkiet/6368d1d45c4ea3e6d9cb – Samuel Kith Jun 05 '19 at 10:17