1

I have a Login page and if the login is successful the user is taken to a landing viewController(VC). I have a navigationController. I pop the login VC and push in the landing VC. The problem I am having is that the login VC persists in the stack as indicated by the left button on the navigation controller which navigates you back to the login page. How do I remove the login VC copletely from the stack so that the navigation controller can not navigate a user back to it once they have logged in?

 self.navigationController?.popViewController(animated: true)

 let landingPage = self.storyboard?.instantiateViewController(withIdentifier: "landingPage") as! 
 LandingViewController

 self.navigationController?.pushViewController(landingPage, animated: true)
3
  • UINavigationController.viewControllers is the navigation stack you can remove one and set the array again to your NavigationController Commented Nov 16, 2017 at 16:30
  • could you eleborate? Commented Nov 16, 2017 at 16:31
  • check the answer provided by @Wez is that what I was talking about Commented Nov 16, 2017 at 16:33

1 Answer 1

7

You can use the setViewControllers method to set the stack like this:

self.navigationController?.setViewControllers([landingPage], animated: true)

You don't need to pop the login view controller first either.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.