[swift][xcode] 複数のstoryBoardを行き来する方法

目次

複数のstoryBoardを行き来する方法

一つのstoryBoardでは運用しきれなくなった時にはstoryBoardを分割すると運用しやすい

storyBoardファイル作成

新規にstoryBoardファイルを作成(例:second.storyboard)

遷移先の設定

新規のstoryBoardの最初に表示させたいviewControllerに「Is Initial View Controller」を設定

storyBoardで最初に表示されるviewを指定する方法

遷移元の設定

遷移元のコードに以下を追加

let storyboard: UIStoryboard = UIStoryboard(name: "[StoryBoardの名前]", bundle: nil)
let next: UIViewController = storyboard.instantiateInitialViewController()!
presentViewController(next, animated: true, completion: nil)

別のStoryBoardの最初ではないViewに遷移したい場合

別のStoryBoardの最初ではないViewに遷移したい場合は以下の通り
StoryBoardの該当ViewContollerに個別のStoryBoardIDを設定しておく

let storyboard: UIStoryboard = UIStoryboard(name: "second", bundle: nil)
let next: UIViewController = storyboard.instantiateViewControllerWithIdentifier("[個別のStoryBoardID]") 
presentViewController(next, animated: true, completion: nil)

遷移元の画面に戻りたい場合

遷移元の画面に戻りたい場合は以下のコードを実装

	
self.dismissViewControllerAnimated(true, completion: nil)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です