TabBar disappears when selectedIndex value changes on iOS 7

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.