0

I am switching the tab bar by using following command

self.tabbarcontroller.selectedIndex=0;

this is working but If I am pushing a another view controller then the switch of tab bar is not happening but if I manually select first view controller then I can see pushed view controller is there.

but why the switch is not happening only when another viewcontroller is pushed on top.

FYI: there is no problem with the way I am pushing the view controler on top of the top view controller because I tried commenting the code for switch the tab bar item and its getting pushed without any problem.

Any help is appreciated.

--

Update:

Here is my code to push the view controller

- (UINavigationController*) rootNavigationController {
    UITabBarController* tabBarController = (UITabBarController*) [[self window] rootViewController];

    return  (UINavigationController*) [tabBarController selectedViewController];
}

  [rootNavigationController pushViewController:newViewController animated:true];
Shiva
  • 545
  • 1
  • 10
  • 41

1 Answers1

0

Same issue happened to me sometimes before. The index is getting changed somehow. To handle such situations, better go with didSelectItem delegate and store the current item as Navigation controller. So no need to use [tabBarController selectedViewController]. Ref: UITabBar(Controller) - Get index of tapped?