2

I wonder how I can remove my old VC's from the stack?

When I start my app there is a Hamburger icon/menu button in the header.

What I want to do is when a user logs into my app I want to set the VC/ Account page to be the root view so that I don't see underlying VC's when looking in the inspector.

So more or less instead of having a back button I want to add a menu button in the header on the account page.

I already tried this but I can't get it to work:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController

let navigationController = self.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewController], animated: true)
ntsh
  • 759
  • 5
  • 19
Kiwo Tew
  • 1,491
  • 1
  • 22
  • 39

1 Answers1

0

I think you can use:

navigationController!.viewControllers.removeAtIndex((navigationController?.viewControllers.count)! - 2)

Use this after your new controller is loaded, so this basically removes the controller previous to the last on the stack. Let me know if you have any issues implementing it.

insys
  • 1,288
  • 13
  • 26
Bruno Garelli
  • 235
  • 2
  • 7