Before we do this, let’s talk about the background. The blogger adds an item to the tabbar. Unfortunately, the tabbar was created by SB, and the blogger himself doesn’t know SB very well, so he is going to add this item in pure code. Tababr = tababR = tababR = tababR = tababR = tababR = tababR = tababR = tababR = tababR

/* If you are a custom tabbar, then it is much easier to say, Bo main said is system tabbar * / / / get the current VC in the tabbar NSMutableArray * newItems = [NSMutableArray arrayWithArray: self. ViewControllers]; // Insert the VC you created [newItems insertObject:[[JumpViewController alloc] init] atIndex:3]; // Because this VC is inherited from the system UITabBarController, so the following method redefine new tababr self.viewControllers = newItems;Copy the code

2. How to click after tabbar item not switching tabbar, but directly jump First of all need to follow two protocols UITabBarControllerDelegate, UITabBarDelegate followed by with the methods:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *) viewController {the if ([tabBarController. TabBar. SelectedItem. Title isEqualToString: @ "jump page"]) {[[NSNotificationCenter defaultCenter] postNotificationName:[NSString stringWithFormat:@"jump%ld",tabTag] object:nil]; return NO; TAB} return YES; } - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {// SelectIndex = selectIndex = selectIndex = selectIndex = selectIndex = selectIndex = selectIndex = selectIndex // Explain why you need to know the current item. // Because the tabbarController created by SB does not have a navigation system, it cannot be directly pushed. Although present can jump, but without navigation, in case of push in the present page, it will be troublesome. So you can't push directly inside a tabbarController; // In addition, to ensure that notifications are sent to the interface you are currently in, rather than being sent and received the same each time you click on it, add the index suffix to make notifications one-to-one. If ([item.title isEqualToString:@" home "]) {tabTag = 0; } if ([item.title isEqualToString:@" category "]) {tabTag = 1; } if ([item.title isEqualToString:@" shopping cart "]) {tabTag = 2; } if ([item.title isEqualToString:@" my "]) {tabTag = 4; } if ([item.title isEqualToString:@" "]) {return; }}Copy the code

The last step is to register the notification in each tabdeVC and perform a push jump, with the notification name suffixed by the index of the current TAB.

Ps: You’ll notice that JumpViewController is not used, it’s just a placeholder.