StoryboardのUnwind SegueにIdentifierをつける
Unwind SegueにIdentifierをつけれることを知らなかったので、メモしておきます。
画面遷移
FirstViewControllerにModalボタンを配置して、押されたら、モーダル表示でナビゲーションコントローラに埋め込んだSecondViewControllerの画面を表示。SecondViewControllerのNextボタンでThirdViewControllerに遷移する。Second、ThirdヴューコントローラのナビゲーションバーにCloseボタンを追加して、押されたら、FirstViewControllerに戻る。FirstViewControllerに戻るところでUnwind Segueを使用。
Unwind Segue接続
Unwind Segueを接続するために、まず戻り先のFirstViewControllerにIBActionを実装する。
@IBAction func unwindAction(segue: UIStoryboardSegue) {
// とりあえず空
}
※これを書かないとCloseボタンからCtrl+ドラッグでExitに繋げようと思っても繋がらないので注意
CloseボタンからCtrl+ドラッグでExitに接続する。
接続が完了したら、View Controller SceneにUnwind segueが追加される。
Unwind segueを選択して、Attribute InspectorのIdentifierにIDをつける。
Unwind segueを接続したViewControllerにprepareForSegueを実装すれば、上でつけたIDがとれる。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { println("\(segue.identifier)") // Unwindが表示される }
ソースはGitHubにあります。