I have a tabBarController with four tabs. From each tab, I can navigate through a series of view controllers. And at the last view controller, I have a 'Done' button, clicking on which I have to be redirected to my initial tabBarController. The code I am using currently to do this is as follows (on button click).
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
if let tabViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as? UITabBarController {
self.navigationController!.pushViewController(tabViewController, animated: false)
}
But I feel this is not correct way since the navigation stack keeps on adding. Instead I would like to clear the navigation stack and show the first tabBarController in the stack. How can I solve this?