LoginSignup
10
6

More than 5 years have passed since last update.

storyboard.instantiateViewControllerWithIdentifier から初期化すると IBOutlet が nil になる

Last updated at Posted at 2016-02-17

呼び出した viewController の view にアクセスすると IBOutlet が生成されるので、 viewController.view を呼び出した後に IBOutlet にアクセスすれば nil にはならない。

let content = storyboard?.instantiateViewControllerWithIdentifier("Storyboard ID")
if let content0 = content! as? HogeViewController{
    let v = content0.view // v は使用しない。もっとスマートなやり方がある気がするけど。
    content0.descriptionLabel.text = "hello world" // descriptionLabel が IBOutlet のビュー
}
10
6
3

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
10
6