LoginSignup
6
3

More than 5 years have passed since last update.

どこから来たのか、遷移元のページを判定させる

Posted at

対象

  • OS 10.13.3
  • Xcode8
  • Swift 3

やったこと

遷移元のページを判定して、画面に表示するものを変えたいので、色々と調べ下記のことがわかりました。忘れないうちに備忘録になります。

move.swift
let count = (self.navigationController?.viewControllers.count)! - 2
        if (self.navigationController?.viewControllers[count] as? [遷移元のContlloer名]) != nil {
              該当のページでない場合の処理
                } else {
                該当ページある場合の処理
        }

わかったこと

なんとなくだけど、わかったのは、「.viewControllers.count」で2つ前に戻ることがポイントらしい。それを元に比較させた感じだと思う

参考

ほぼ、こちらの方の方法を参考にさせてもらいました。
swiftで遷移元のviewcontrollerのインスタンスを取得する方法

6
3
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
6
3