title: Swift Changing Navigation ViewController stack (programatically)
body: <p>I'm having some trouble with the logic in my application.</p>
  
  <p>I have been looking for a way to change the navigation controller's viewcontroller stack.</p>
  
  <p>For several reasons.</p>
  
  <p>One, I have a login and sign up page, which each have buttons pushing to the other view controller. Creating an /infinite/ loop being able to go between them.</p>
  
  <p>I also need to change the topViewController, to my dashboard_VC after the user has logged in. So the back button to the login page doesn't show up...</p>
  
  <p>I've been trying to find a solution for a while. I've mainly been looking at rootViewController, until I realized that's probably not the one I'm looking for since my rootViewController is my navigationController and not my first View Controller in the stack.</p>
  
  <p>So I tried to change the stack with this:</p>
  
  <pre><code>self.navigationController?.setViewControllers([LandingPageVC(),LoginVC()], animated: false)
  </code></pre>
  
  <p>However this causes an infinite loop. Since It runs every time this viewController is loaded, and when it's run, it seems to reload all the viewcontrollers...</p>
  
  <p>I tried putting it in viewDidAppearAnimated instead. But same results. I've since then been trying to put this outside the viewDidLoad or Appear methods. but I can't get it to work since the class doesn't have "navigationController". </p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>(I'm not using storyboards)</p>