Warning: Attempt to present * on * whose view is not in the window hierarchy - swift

前端 未结 17 972
花落未央
花落未央 2020-11-30 22:03

I\'m trying to present a ViewController if there is any saved data in the data model. But I get the following error:

Warning: A

17条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 22:07

    let storyboard = UIStoryboard(name: "test", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "teststoryboard") as UIViewController
    UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
    

    This seemed to work to make sure it's the top most view.

    I was getting an error

    Warning: Attempt to present myapp.testController: 0x7fdd01703990 on myapp.testController: 0x7fdd01703690 whose view is not in the window hierarchy!

    Hope this helps others with swift 3

提交回复
热议问题