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

前端 未结 17 999
花落未央
花落未央 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条回答
  •  猫巷女王i
    2020-11-30 22:24

    For swift 3.0 and above

    public static func getTopViewController() -> UIViewController?{
    if var topController = UIApplication.shared.keyWindow?.rootViewController
    {
      while (topController.presentedViewController != nil)
      {
        topController = topController.presentedViewController!
      }
      return topController
    }
    return nil}
    

提交回复
热议问题