打开和关闭 UINavigationController

Opening and closing UINavigationController

我知道它可能已经写在某个地方关于这个问题,但我找不到解决方案并且已经解决这个问题几天了。

我有一个带有 UITabbar 和 4 个 UINavigationController 的应用程序。 在其中一个 UINavigationController 上有一个 UIViewController,带有一个按钮,该按钮可以通过模态转换打开另一个 UINavigationController。打开时一切正常,但在使用代码从其 UIViewController 关闭最后一个 NC 后:

self.dismiss(animated: false, completion: nil) 

self.navigationController?.dismiss(animated: false, completion: nil)

我遇到了问题。 无论接下来我做什么,我都会收到警告 Unbalanced calls to begin/end appearance transitions for and on UIViewControllers methods viewWillAppear and viewDidAppear don't get called .但是为了清楚起见,只有当我打开一个新视图时我才不会遇到这个问题,如果我只是在选项卡之间切换到其他 UINavigationViewController.

我也会遇到这个问题

我已经检查了我读到的一种可能性,我确定我不会打开一个东西两次。

我就是想不通是多个NavigationControllers的问题还是我关闭它的方式问题还是什么。

任何建议都会有所帮助。

编辑 1:

忘记说了,UINavigationController 是通过模式转场打开的,不是通过代码打开的。

所有NC至少有一个VC(tabbar上有4个,后面打开的也有)

编辑 2:

取消 VC 的代码是 运行 on the last opened VC on last opened NC (not one of the tabbar NC) to return to one标签栏 NC/ his VC。 为了确保我会再写一遍

TC -> NC    NC    NC    NC
      |     |     |     |
      VC    VC    VC    VC
       |
      NC
       |
      VC - the one that calls dismiss to return to previous VC

令人沮丧的是,在我打开另一个 UINavigationController 之前一切正常,但之后问题就开始了。或者也添加我注意到的另一件事,问题出现在模态呈现另一个控制器之后,无论是 UINavigation 还是正常 ViewController.

编辑 3:

感谢@kgkoutio,问题解决了,我犯的错误是我没有在某处调用super.viewDidLoad和super.viewWillAppear。将它添加到所有 VC 之后,问题就消失了。

再次感谢@kgkoutio

您的代码解雇了 NC 而不是 VC。当应用程序启动时,TabBar 会使用您的导航控制器集进行初始化。考虑关闭 UIViewController 而不是 NC:

self.navigationController.topViewController?.dismiss(animated: false, completion: nil)