需求:当点击tabBar下面的item的时候,判断是否登录,没有登录跳转登录页面
听起来很简单,来实现代码:
//UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController*)tabBarController shouldSelectViewController:(UIViewController*)viewController {
if(USERINFO.isUserLogin) {
LoginViewController*loginVC = [[LoginViewControlleralloc]init];
loginVC.hidesBottomBarWhenPushed=YES;
[self.navigationControllerpushViewController:loginVCanimated:YES];
return
NO;
}
return YES;
}
结果你会发现不如愿了,点击没反应了。
解决方法:跳转用modal,代码改为
[selfpresentViewController:[[UINvigationControlleralloc]initWithRootViewController:loginVC]animated:YEScompletion:nil];