I have a UITabBarController with two UINavigationController, when I switch from one TabBarItem to other, the previously selected view controller should pop to its root view controller.
1 Answer
Implement the UITabBarControllerDelegate tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) method like this:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { if let navigationController = viewController as? UINavigationController{ navigationController.popToRootViewController(animated: false) } return true }