简体   繁体   中英

iOS: popToRootViewControllerAnimated second item in tab bar

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

在此处输入图片说明

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM