You can set the viewControllers
property of your navigationController
and if you'd like to animate that transition it's also possible too.
navigationController?.viewControllers = []
navigationController?.setViewControllers([], animated: true)
In your example, when you get to C you'd have
navigationController?.viewControllers = [self]
which would remove A and B from the stack once you've got to C.. you might have to put it in viewDidAppear
but make sure you only do that once, unless you want it to flush the stack every time C ends up on the screen.
var initialLoad:Bool = true
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if initialLoad {
initialLoad = false
navigationController?.viewControllers = [self]
}
}
Alternatively when you're about to push to C you could try instead of pushViewController
let cViewController = CViewController()
navigationController?.setViewControllers([cViewController], animated: true)
and I believe that'll push you forward and then remove A and B from the stack. Sometimes depending on the current state of the stack that'll animate a pop though