1

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 1

7

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 } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.