Denis Mertsalov
Denis Mertsalov

Reputation: 1

Return to root controller from another tab

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!

Upvotes: 0

Views: 879

Answers (2)

rksruthi
rksruthi

Reputation: 21

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)
    }
}

Upvotes: 2

Shiva Reddy
Shiva Reddy

Reputation: 456

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];

    }
}

Upvotes: 0

Related Questions