LoginSignup
1
4

More than 5 years have passed since last update.

NavigationControllerで何回かpushしたあとのViewControllerで2つ以上ViewControllerをpopして戻る

Last updated at Posted at 2017-02-10

2回戻る例。

ViewController.swift
guard let navigationController = navigationController else {
    return
}
let viewControllers: [UIViewController] = navigationController.viewControllers as [UIViewController]
navigationController.popToViewController(viewControllers[viewControllers.count - 3], animated: true)

...1回だけ戻る例も載せておきます。

ViewController.swift
guard let switchViewController = navigationController?.viewControllers[1] else {
    return
}
navigationController?.popToViewController(switchViewController, animated: true)

参考

Pop 2 view controllers in Nav Controller in Swift
http://stackoverflow.com/questions/26132658/pop-2-view-controllers-in-nav-controller-in-swift

Swift popToViewController
http://stackoverflow.com/questions/28190070/swift-poptoviewcontroller

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4