Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

后端 未结 30 3821
一整个雨季
一整个雨季 2020-11-21 23:39

Just started using Xcode 4.5 and I got this error in the console:

Warning: Attempt to present < finishViewController: 0x1e56e0a0 > on < ViewCont

30条回答
  •  天命终不由人
    2020-11-22 00:03

    In my situation, I was not able to put mine in a class override. So, here is what I got:

    let viewController = self // I had viewController passed in as a function,
                              // but otherwise you can do this
    
    
    // Present the view controller
    let currentViewController = UIApplication.shared.keyWindow?.rootViewController
    currentViewController?.dismiss(animated: true, completion: nil)
    
    if viewController.presentedViewController == nil {
        currentViewController?.present(alert, animated: true, completion: nil)
    } else {
        viewController.present(alert, animated: true, completion: nil)
    }
    

提交回复
热议问题