views:

223

answers:

1

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.tabBarController.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?

A: 

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.

Andiih
Thanks for answering!Does this mean I'll have to start a new app from scratch and build something new in Interface Builder, wire it up again, and paste in the old code and change everything to do with the tab bar?If so, what is the layout/solution that will give me the least limitations?I chose the tab bar solution so that all three views would have a chance to load simultaneously at startup, so that they'd be loaded when switched to. But maybe that's possible with all other solutions as well?I'd be happy to 'fake' the slide, for example by 'moving' the table view. Suggestions, anyone?
Henrik Erlandsson
Kludge solution maybe - could I add a copy of the table view on top of the map view, switch to it instantaneously as now, and slide the copy out of sight and then remove it? Thoughts?
Henrik Erlandsson
You don't need to start a new app from scratch - I just find the blank App a good place to understand what is going on and where to get the code from!Your cludge may also work, although I'd add the second tabs view as a subview (all be it off screen) to your current view, slide it on then switch tabs, then remove it from the superview again to get back to the original state (but now looking at the second tab).
Andiih