faruk.kuscan faruk.kuscan - 2 months ago 20
Objective-C Question

TabBar disappears when selectedIndex value changes on iOS 7

I have an iOS application which was build with 6.1 base sdk. Now I am moving the application to next SDK 7.0. I have a tabbar which has 5 items on it. Each tab is a navigation controller. Also, each view controller which is pushed into these navigation controllers hides the tab bar with the method

[self setHidesBottomBarWhenPushed:YES];


When I am at the second tab, i press a button and after a web connection, it pops to root view controller and updates the selectedIndex of tabbarcontroller. The main tabbar controller is accessed with its reference in appdelegate. The thing happening is when selected index is 1 and then I set it as 2 the tab bar disappears. However, when it is 2 and i set it 2 again there is no problem.

[self.application.tabBarController setSelectedIndex:2];


This problem only occurs in iOS 7 simulator. When I simulate on iOS 6 simulator it is not happening. Also my tabbar items are custom, i don't know if it has something to do with it.

What might be the problem?

Answer

I found the solution. My code was the following at first. Both navigation controllers in the tabbar controller popped to root view controller.

[self.navigationController popToRootViewControllerAnimated:YES];
[self.application.tabBarController setSelectedIndex:2];
[self.application.tabBarController.secondTabNavigationController popToRootViewControllerAnimated:YES];

When I rearranged the orders of popToRootViewController methods, the problem disappeared.

[self.application.tabBarController setSelectedIndex:2];
[self.application.tabBarController.secondTabNavigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];

The first one works fine in iOS 6 devices but it does not in iOS 7 devices. Second one works for all.