I have an app with three tabs that switch views instantaneously when the user taps them. The first view is a table view selecting which 'location type' to filter by, to only show those pins (add those annotations) to the second view, a MapView.
When a table cell is clicked, it switches instantaneously to the mapview, using this code:
self.tab开发者_开发技巧BarController.selectedIndex=1;
However, I would like to do this with a slide-in-from-right animation, like the one you get when drilling down a hierarchy of table views.
I tried this:
[self.navigationController pushViewController:[self.tabBarController.viewControllers objectAtIndex:1] animated:YES];
which compiles without error or warning, but does not switch views.
How do I 'apply' a navigation controller 'onto' a tab bar controller? Or is there some way to select another viewcontroller and specify an animation?
I don't think you are going to be able to do that with a tab bar controller as there is no API to manage the animations. Your choices are either to swap out the tab bar and build something similar using buttons, in which case you can manage your own view stack, or to forgoe the animation and just switch views as you are doing.
An alternative approach is to display the map as part of the nav-controller stack belonging to your current tab - (assuming you have a nav controller stack) but that's not acutually going to swap tabs for you, just move you to a new place on your current stack.
精彩评论