UITabBarController点击UITabBarItem 禁止跳转 iOS

写在下面类里无效,切记

class CJZFTabBarViewController: UITabBarController {}

 

需要写在appdelegate或者基类里,可以拦截 tabbaritem 是否被选中。

选中了后,才会走  didSelect 代理方法。

 

复制代码
@interface BaseViewController ()<UITabBarControllerDelegate>
 
@end

//判断是否跳转
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if ([viewController.tabBarItem.title isEqualToString:@"我的"]) {
        return NO;
    }else{
        return YES;
    }
}

- (void)viewDidLoad{
    [super viewDidLoad];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UITabBarController *tabViewController = (UITabBarController *) appDelegate.window.rootViewController;
    tabViewController.delegate = self;
}
复制代码

 

posted @   黄增松  阅读(62)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示