UINavigationController
Swift

UINavigationControllerで2つ以上前の画面に戻る方法

More than 1 year has passed since last update.

参考

How do I pop two views at once from a navigation controller?

実装方法

// rootViewControllerに戻る
navigationController?.popToViewController(navigationController!.viewControllers[0], animated: true)
// または
navigationController?.popToRootViewControllerAnimated(true)

// rootViewControllerの1つ先のViewControllerに戻る
navigationController?.popToViewController(navigationController!.viewControllers[1], animated: true)

// rootViewControllerの2つ先のViewControllerに戻る
navigationController?.popToViewController(navigationController!.viewControllers[2], animated: true)

// 一つ前のViewControllerに戻る
navigationController?.popViewControllerAnimated(true)