iOS 拦截TabBarItem点击事件

在UITabBarControllerDelegate 的代理方法,

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0);中做自己的操作;

如果不想进入点击的控制器中,可以return No;

例如

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0) {

BaseNaviController *navCtrl = (BaseNaviController *)viewController;

UIViewController *rootCtrl = navCtrl.topViewController;

if([rootCtrl isKindOfClass:[RegistViewController class]]) {

[self _registAction];

BaseNaviController *navCtrl2 = self.viewControllers[0];

self.selectedViewController = navCtrl2;

self.selectedIndex = 0;

return NO;

}

return YES;

}

你可能感兴趣的:(iOS 拦截TabBarItem点击事件)