【问题标题】:swift - How can I reach 2nd tab navigation stack from 1st tab?swift - 如何从第一个选项卡到达第二个选项卡导航堆栈?
【发布时间】:2019-01-09 10:43:51
【问题描述】:

我有一个带有 2 个选项卡的 TabBarController,每个选项卡都是 NavigationControllerUIViewControllers。

而且,当我在第一个选项卡上执行某些操作时,我需要能够将第二个选项卡上的 UIViews 之一移动到堆栈顶部。

如何从第一个选项卡到达第二个选项卡导航堆栈?

我不想切换到第二个标签,只将其 UIview 移动到其堆栈顶部

附言例如,

    TabbarController
       Tab1
         NavigationController1
          ViewController1
          ViewController2
       Tab2
         NavigationController2
          ViewController3

所以从ViewController3可以把ViewController2放到栈顶NavigationController1

【问题讨论】:

  • 你想显示第二个标签吗?还是只需要在第二个 VC 中更改导航控制器堆栈?
  • @RobertDresler 只是改变堆栈,没有路由
  • 不点击任何地方你想去第二个标签? @nastassia
  • self.tabBarController?.selectedIndex = 0 你可以像这样实现 @nastassia 0 是你的第二个标签然后你可以直接移动到你的 viewController1
  • @AbhishekJadhav 我不想移动到第二个选项卡,只将它的 UIview 移动到它的堆栈顶部

标签: swift uinavigationcontroller uitabbarcontroller uitabbar


【解决方案1】:

ViewController3 获取嵌入在第一个选项卡中的导航控制器的参考 (NavigationController1),然后尝试将其向下转换为 UINavigationController。然后在这个导航控制器上调用popToRootViewController(animated:)

if let navigationController = tabBarController?.viewControllers?[0] as? UINavigationController {
    navigationController.popToRootViewController(animated: true) // or `animated: false`
}

【讨论】:

    【解决方案2】:

    希望对你有帮助!!

    self.tabBarController?.selectedIndex = 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2012-09-15
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多