选中选项卡后返回到根视图

时间:2013-12-12 13:53:04

标签: ios objective-c uitabbarcontroller uitabbar

参考this link我在UITabDelegate添加了UITabBarControllerDelegateAppDelegate.h并添加了

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if ([viewController isKindOfClass:[UINavigationController class]])
    {
        [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
    }
}
AppDelegate.m中的

。问题仍未解决。我在我的项目中使用XIB并处理登录和注销以相应地启用和禁用标签栏。

1 个答案:

答案 0 :(得分:2)

你应该这样写:

if ([viewController isKindOfClass:[ClassName_Of_Selected_ViewController class]])
    {
        //[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
        [viewController.navigationController popToRootViewControllerAnimated:NO];
    }