LoginSignup
6
7

More than 5 years have passed since last update.

複数画面A、Bから呼ばれる画面Cを閉じた時にunwindを使って遷移元に戻す方法

Last updated at Posted at 2016-02-15

やりたいこと

複数画面A、Bから呼ばれる画面Cを閉じた時にunwindを使って遷移元に戻す。
遷移元の「@IBAction func unwind(segue: UIStoryboardSegue)」で処理を行いたいので「dismissViewControllerAnimated」は使いたくない。

画面

スクリーンショット 2016-02-15 14.36.10.png

左上:画面A 右上:画面B 下:画面C

やり方

単純に「@IBAction func unwind:」の名前を同じにするだけでできた。
ここまで辿り着くのに凄い時間かかったよorz

画面A
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func unwind(segue: UIStoryboardSegue)
    {
    }

    @IBAction func click(sender: UIButton)
    {
        self.performSegueWithIdentifier("toC", sender: nil)
    }

    @IBAction func click2(sender: UIButton)
    {
        self.performSegueWithIdentifier("toB", sender: nil)
    }
}
画面B
class View2Controller: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func unwind(segue: UIStoryboardSegue)
    {
    }

    @IBAction func click(sender: UIButton)
    {
        self.performSegueWithIdentifier("toC", sender: nil)
    }
}
画面C
class View3Controller: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
6
7
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
7