Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@keisei_1092

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

More than 3 years have passed since last update.

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

4
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
keisei_1092
よろしくお願いします。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?