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 @ 2024-05-16 09:41  黄增松  阅读(37)  评论(0编辑  收藏  举报