项目里面在点击tabbarItem的时候需要判断是否是登录状态,如果未登录直接跳转登录页面,如果已登录则直接进入。

 

具体做法是:

1:在持有TabbarController的类中, 注入代理UITabbarControllerDelegate

2:TableBarController *tabBarC = [[TableBarController alloc]init];

 tabBarC.delegate = self;

3:实现tabbarController的代理方法

 

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

{

     NSLog(@"--tabbaritem.title--%@",viewController.tabBarItem.title);

    //这里我判断的是当前点击的tabBarItem的标题

    if ([viewController.tabBarItem.title isEqualToString:@"我的"]) {

        //如果用户ID存在的话,说明已登陆

        if (userl.ID) {

            return YES;

        }

        else

        {

            //跳到登录页面

            LoginViewControllerNew *login = [[LoginViewControllerNew alloc] init];

            //隐藏tabbar

            login.hidesBottomBarWhenPushed = YES;

            [((UINavigationController *)tabBarController.selectedViewController) presentViewController:login animated:YES completion:nil];

 

            return NO;

        }

    }

    else

        return YES;

}

 

posted on 2016-01-27 14:18  i兮兮  阅读(703)  评论(0编辑  收藏  举报