user2924482
user2924482

Reputation: 9120

iOS: popToRootViewControllerAnimated second item in tab bar

I'm trying to implement a tab bar in iOS application:

enter image description here

But when users tab item 1 I need to release the second viewController.

I setup UITabBarControllerDelegate

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
{

    if (tabBarController.selectedIndex == 0)
    {
        UINavigationController *navController = (UINavigationController*)viewController;
        [navController popToRootViewControllerAnimated:NO];
    }

}

But when I tab in item one I get this error:

[ViewController popToRootViewControllerAnimated:]: unrecognized selector sent to instance

My question is. What I'm doing wrong. I'm trying to release the second item in my tab bar. There is another way I can release the second item in my tab bar?

Upvotes: 0

Views: 275

Answers (1)

beyowulf
beyowulf

Reputation: 15331

Think you mean.

if (tabBarController.selectedIndex == 0)
        {
            UINavigationController *navController = [tabBarController.viewControllers objectAtIndex:1];
            [navController popToRootViewControllerAnimated:NO];
        }

But even that won't do what you want. You need to set navController's rootViewController with a new instance of RootViewController.

Upvotes: 1

Related Questions