我如何清理 UINavigationBar 转换历史记录?

How I could clean UINavigationBar transitions history?

我目前有父母 "menu" TableViewUINavigationBar 并且从每个 cell 有一个 segues by reference outlet 到 3 相似 Views 有不同的信息。

在每个 View 中有一个 buttons 到其他 2 Views.

button 的 segue 都会打开另一个 View

问题: 从每个 View UINavigationBarback button returns 我到以前的 View 但我试图让 back button 变成 "menu"。

额外的 Bar Button Item 和它的 segue 效果非常接近,但 segue 动画不像 UINavigationController.

如何清理 UINavigationBar 过渡到初始视图的历史记录?

您可以尝试弹出到根视图控制器,或者您可以编辑导航控制器 viewControllers 属性 和 remove/add 之间的一些 VC。

你也可以试试Unwind Segue机制。

下面是navigation controller提供的pop操作的一些方法(函数)。他们从弹出的导航堆栈返回可选的 UIViewController(实例)。

open func popViewController(animated: Bool) -> UIViewController? // Returns the popped controller.

open func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? // Pops view controllers until the one specified is on top. Returns the popped controllers.

open func popToRootViewController(animated: Bool) -> [UIViewController]?

这里是示例代码,作为您查询的解决方案::

// if you want to back to root of your app
if let rootNavigationController = self.window?.rootViewController as? UINavigationController {
     rootNavigationController.popToRootViewControllerAnimated(true)
}

// But if you want to back to root of your current navigation 
if let viewcontroller = self.storyboard?.instantiateViewController(withIdentifier: "NewViewController") as? NewViewController { // or instantiate view controller using any other method
     viewcontroller.navigationController?.popToRootViewControllerAnimated(true)
}