美文网首页
tabBarController

tabBarController

作者: kangomake | 来源:发表于2019-02-27 11:49 被阅读0次

1.在Controller中获取当前的tabbarController

方法一:MainTabBarController *mt=(MainTabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;

方法二:self.navigationController.tabBarController

2. 跳转到指定的TabBarViewController中的某一个VIewController

[self dismissViewControllerAnimated:YES completion:^{
  // 这是从一个模态出来的页面跳到tabbar的某一个页面
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        UITabBarController *tabViewController = (UITabBarController *) appDelegate.window.rootViewController;
        [tabViewController setSelectedIndex:2];
    }];

3.未登录时点击tabbar跳转到登录页面
在Controller中遵守协议 <UITabBarControllerDelegate>
指定代理 self.navigationController.tabBarController.delegate = self;

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    
    if([viewController.tabBarItem.title isEqualToString:@"mine"]){
        
        BOOL isLogin = ((AppDelegate *)[UIApplication sharedApplication].delegate).isLogin;
        if(!isLogin){
            
            HRLoginViewController * login = [[HRLoginViewController alloc]init];
            HRNavigationController *nav = [[HRNavigationController alloc] initWithRootViewController:login];
            [self presentViewController:nav animated:YES completion:nil];
            
            return NO;
        }else
            return YES;
    }else
        return YES;
    
}

相关文章

网友评论

      本文标题:tabBarController

      本文链接:https://www.haomeiwen.com/subject/stvxuqtx.html