やりたいこと
複数画面A、Bから呼ばれる画面Cを閉じた時にunwindを使って遷移元に戻す。
遷移元の「@IBAction func unwind(segue: UIStoryboardSegue)」で処理を行いたいので「dismissViewControllerAnimated」は使いたくない。
画面
左上:画面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.
}
}