我现在有这个错误:
Warning: Attempt to present <UINavigationController: 0x10d80b800> on <UINavigationController: 0x109891a00> whose view is not in the window hierarchy!
我以前见过这个,通常它与viewDidLoad
相对于另一个试图呈现的地方,但在这里并非如此。
我的流程:
LoginViewController(不是UINavigationController):
self.performSegue(withIdentifier: "GoToMainVC", sender: nil)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
if identifier == "GoToMainVC" {
segue.destination.transitioningDelegate = self
segue.destination.modalPresentationStyle = .custom
}
}
}
ProfileViewController(它是UINavigationController中的ViewController):
self.presentingViewController?.dismiss(animated: true)
在此之前,我还有self.navigationController?.dismiss(animated: true)
的ProfileViewController,但它不重要。
当我的应用程序第一次通过segue时,一切都很好,UINavigationController为<UINavigationController: 0x10d81a000>
。
在我完成解雇并尝试再次发出警告后,我收到上面的警告,其中<UINavigationController: 0x10d81a000>
正试图在<UINavigationController: 0x109891a00>
上展示。我不知道第二个UINavigationController来自哪里,因为LoginViewController不是UINavigationController。
完全被难住了。
更新:我通过明确使用self.presentViewController
而不是segue修复了我的错误,但我离开了这里......因为这对我来说非常奇怪而且我是想知道为什么会这样。