13
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swift初心者:画面推移時の「whose view is not in the window hierarchy!」の対処方法

Last updated at Posted at 2018-02-17

#はじめに
初歩的なエラーかと思いますが、初心者のため記録として残したいと思います。

##①whose view is not in the window hierarchy!

ログ
<famousVoiceApp.ViewController: 0x7f8b16d0ba30> whose view is not in the window hierarchy!`

ログ内に表示される上記内容は画面推移のメソッドをviewDidLoad内に記載することにより発生するエラーです。

override func viewDidLoad() {
     super.viewDidLoad()
        let SecondViewController = self.storyboard?.instantiateViewController(withIdentifier: "Second")
        self.present(SecondViewController!, animated: false, completion: nil)
}

ではなく、

override func viewDidAppear(_ animated: Bool) {
     super.viewDidAppear(animated)
       let SecondViewController = self.storyboard?.instantiateViewController(withIdentifier: "Second")
       self.present(SecondViewController!, animated: false, completion: nil)
}

以上のようにviewDidAppear内に定義することでエラーが解消されるかと思います。

13
15
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
13
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?