写在下面类里无效,切记
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; }
标签:UITabBarItem,viewController,iOS,tabBarController,viewDidLoad,跳转,UITabBarControll From: https://www.cnblogs.com/huangzs/p/18195350