0

I am having trouble with my UITabBarController. In my application I have 4 tabs, each corresponding to their own root view controller. I can change tabs with no problem and the state of the tab is intact when I switch back. However, if I were to re-select the same tab, the view controller refreshes taking me back to the root.

This is something that I wish to disable in my app and I am wondering if there is any possible way of doing this?

Andy Shephard
  • 1,726
  • 17
  • 26

1 Answers1

1

Upon researching the issue further, I discovered the solution to this issue was to add the following code:

First add UITabBarControllerDelegate to the header file (in my case, AppDelegate), then add to the main file:

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

bool r = ([tabBarController.viewControllers indexOfObject:viewController] != tabBarController.selectedIndex);

return r;

}

Andy Shephard
  • 1,726
  • 17
  • 26