Return to root controller from another tab

897 views Asked by At
  • First Tab
    • Navigation Controller
    • Table controller
    • Details Controller
  • Second Tab
    • View Controller

Hello!

a user on the First tab looks Table controller and the opens Detail controller and then proceeds to the Second tab and there doing something. then returning to the First tab he sees Detail controller but I needed that there was a Table controller! This can be done by double tap to First tab icon but how to do it programmatically?

Thanks for the help!

2

There are 2 answers

2
rksruthi On

You can use the tabbar delegate like this:

func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
    if tabBarController.selectedIndex == 0 {
        let navigationController = viewController as? UINavigationController
        navigationController?.popToRootViewControllerAnimated(true)
    }
}
0
Shiva Reddy On

Use TabBar Delegate method for this

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    //identify the index of first tab 
    if ([tabBarController selectedIndex] == [[tabBarController viewControllers]count]-1) {
            [(UINavigationController *)self.selectedViewController popToRootViewControllerAnimated:YES];

    }
}