LoginSignup
8
8

More than 5 years have passed since last update.

コード内からストーリーボード上のビューコントローラを使う

Last updated at Posted at 2014-12-23

ストーリーボード上でStoryboard IDを付けておく

ss1.png

ViewControllerのIdentity inspector

コード内でストーリーボードを生成し、IDで呼び出す

// MainStoryboard.storyboardの生成
let storyBoard: UIStoryboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
// ここでID指定して自前のNavigationControllerクラスとして生成
var nav = storyBoard.instantiateViewControllerWithIdentifier("CommentNavigationController") as NavigationController 
// パラメータ渡したいのでNavigationControllerの中身のviewControllerを生成
let topView = nav.topViewController as CommentViewController 
// プロパティに渡す
topView.parameter = hoge
8
8
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
8
8