swift - 如何从第一个选项卡到达第二个选项卡导航堆栈?
swift - How can I reach 2nd tab navigation stack from 1st tab?
我有一个带有 2 个选项卡的 TabBarController
,每个选项卡都是 NavigationController
和 UIViewController
。
而且,当我在第一个选项卡上执行某些操作时,我需要能够将第二个选项卡上的 UIView
之一移动到堆栈的顶部。
如何从第一个选项卡到达第二个选项卡导航堆栈?
我不想切换到第二个选项卡,只将其 UIview
移到其堆栈的顶部
p.s。例如,
TabbarController
Tab1
NavigationController1
ViewController1
ViewController2
Tab2
NavigationController2
ViewController3
所以从ViewController3
可以把ViewController2
放到栈顶NavigationController1
从 ViewController3
获取第一个选项卡中嵌入的导航控制器的参考 (NavigationController1
),然后尝试将其向下转换为 UINavigationController
。然后在这个导航控制器上调用 popToRootViewController(animated:)
if let navigationController = tabBarController?.viewControllers?[0] as? UINavigationController {
navigationController.popToRootViewController(animated: true) // or `animated: false`
}
希望对您有所帮助!!
self.tabBarController?.selectedIndex = 0
我有一个带有 2 个选项卡的 TabBarController
,每个选项卡都是 NavigationController
和 UIViewController
。
而且,当我在第一个选项卡上执行某些操作时,我需要能够将第二个选项卡上的 UIView
之一移动到堆栈的顶部。
如何从第一个选项卡到达第二个选项卡导航堆栈?
我不想切换到第二个选项卡,只将其 UIview
移到其堆栈的顶部
p.s。例如,
TabbarController
Tab1
NavigationController1
ViewController1
ViewController2
Tab2
NavigationController2
ViewController3
所以从ViewController3
可以把ViewController2
放到栈顶NavigationController1
从 ViewController3
获取第一个选项卡中嵌入的导航控制器的参考 (NavigationController1
),然后尝试将其向下转换为 UINavigationController
。然后在这个导航控制器上调用 popToRootViewController(animated:)
if let navigationController = tabBarController?.viewControllers?[0] as? UINavigationController {
navigationController.popToRootViewController(animated: true) // or `animated: false`
}
希望对您有所帮助!!
self.tabBarController?.selectedIndex = 0