How to popToRootViewController with multiple viewControllers on the navigationController stack and show only one transition?

Viewed 220

How to popToRootViewController having multiple viewControllers (2) on the navigationController stack and show only one transition?

For example VC A pushes VC B, C onto the navigation stack. Now I want to have a smooth animated transition from C to A without showing B at all.

I've tried lots of things but always I see B.

For example I've tried:

self.navigationController?.viewControllers.removeLast()
self.navigationController?.popToRootViewController(animated: true)

And:

func popBack<T: UIViewController>(toControllerType: T.Type) {
   if var viewControllers: [UIViewController] = self.navigationController?.viewControllers {
      viewControllers = viewControllers.reversed()
      for currentViewController in viewControllers {
         if currentViewController .isKind(of: toControllerType) {
            self.navigationController?.popToViewController(currentViewController, animated: true)
            break
         }
       }
   }
}

As well as popping with animated false then popping with animated true, but always I see B. There are a lot of SO threads and I've attempted more than just what I've put above.

1 Answers

Storyboard and views

self.navigationController?.popToRootViewController(animated: true)

Only using this line worked for me.

Related