Search code examples
objective-cxcodeuitabbarcontrolleruitabbaritem

Click button push to another view controller with automatically highlight Tab Button Item


When I click the cross button in more view controller the action will push to home view controller.

image1

But the tab bar did not automatically highlight the home tab bar. The result I want is like this

image2

The code below is the action push to home view controller

-(void)tapDetected{
    HomeMainViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier: @ "homeVC"];
    [self.navigationController pushViewController:vc animated: YES];
}

Solution

  • I assume you are using a UITabBarController. If yes, try this :

        UITabBarController* vc = (UITabBarController*) self.parentViewController;
    
        if( vc && [vc isKindOfClass:[MainTabViewController class]] )
        {
            [vc setSelectedIndex:0];
        }