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?
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.
If you do need to first pop-to-root-VC and only then switch to another tab bar there is a great workaround for it by using false in the animated param:
// Assuming the current selected index might be a non-zero value
tabBarController.popToRootViewControllerAnimated(false)
tabBarController.selectedIndex = 0
This way you can first popToRootViewControllerAnimated
and only then programatically switch to your desired tab bar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With