0

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];
}
garyh
  • 2,782
  • 1
  • 26
  • 28
Nur II
  • 173
  • 1
  • 2
  • 16
  • I have place your images inline so it's easier to see what the problem is. Maybe you could reduce the large image to just the relevent detail as there's a lot of empty space there. Also can you show your code for what you have attempted in order to rectify the problem. – garyh Jun 23 '17 at 08:35
  • thanks for the guide =) – Nur II Jun 23 '17 at 10:03

1 Answers1

0

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];
    }
qpc
  • 53
  • 5
  • I should put this code in the More View Controller or Tab Bar View Controller? – Nur II Jun 23 '17 at 01:41
  • MoreViewController is a child of the UITabBarController (again, assuming you are using this controller). So parentViewController will return a UITabBarController. You just apply a cast to access it's setSelectedIndex method. – qpc Jun 23 '17 at 07:19
  • Also, instead of just "0", you should declare a constant, just to get clean code. – qpc Jun 23 '17 at 07:20