LoginSignup
35
32

More than 5 years have passed since last update.

StoryBoardのViewControllerをインスタンス化する

Last updated at Posted at 2015-06-29
swift

let mainVC = MainViewController()

上記の記載では、ストーリーボードで定義したボタンなどの配置まで紐付けることができないので、下記のようにストーリーボードをインスタンス化させる。

  1. Storyboard上で、ViewControllerを定義する

  2. Storyboard上で、ViewControllerのStoryboardIDを定義する

  3. 呼び出したいクラスで下記のコードを実行する

swift

var storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainVC = storyboard.instantiateViewControllerWithIdentifier("MainViewController") as! MainViewController
35
32
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
35
32