【问题标题】:How I could clean UINavigationBar transitions history?我如何清理 UINavigationBar 转换历史?
【发布时间】:2018-06-28 02:21:38
【问题描述】:

我目前有父母“菜单”TableViewUINavigationBar,并且从每个 cell 有一个由 reference outlet 到 3 个相似的 Views 的序列,具有不同的信息。

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

每个button 的segue 都会打开另一个View

问题: 从每个View UINavigationBarback button 将我返回到以前的View 但我试图将back button 设置为“菜单”。

附加的Bar Button Item 和segue 从它产生非常接近的效果,但segue 动画不像UINavigationController 中那样。

如何将 UINavigationBar 转换历史记录清除到初始视图?

【问题讨论】:

  • 我想你正在寻找 pop to root view controller (animated:)

标签: ios swift uitableview uinavigationcontroller segue


【解决方案1】:

您可以尝试弹出到根视图控制器,或者您可以编辑导航控制器viewControllers 属性并在其间删除/添加一些VC。

你也可以试试 Unwind Segue 机制。

【讨论】:

    【解决方案2】:

    以下是导航控制器为弹出操作提供的一些方法(功能)。他们从它的导航堆栈中返回可选的 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)
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多