iosswiftuiviewcontrolleruikitpoptoviewcontroller

Does "popToViewController" pop all the view controllers in between too?


Navigation controllers have a stack of view controllers. So, let us say the stack looks like this:

[Home, friends, highScores, Add, fullList]

Therefore I am currently on fullList, the top view Controller in the stack. Now if I do:

var stack = navigationController!.viewControllers
navigationController?.popToViewController(stack[1] as! UIViewController, animated: true)

i.e I pop to the view Controller called friends, does it also pop the view Controllers called highScores and add aswell or leave those and skip down into the stack?


Solution

  • Pops view controllers until the specified view controller is at the top of the navigation stack.

    Yes.