views:

98

answers:

3

I'm working on an application that I'd like to use the same hybrid of navigation and tab bars that the iPod/Music application uses to navigate playlists.

Basically:

  • Navigation to deal with delving deeper into a particular list tree.
  • A tab bar along the bottom to switch between lists, which appears on most/all subscreens.
  • The tab bar's contents are constant between all screens.
  • The tab bar's reaction to being tapped is the same on all screens: it pops the user all the way back to the root and puts them on that list.

Navigation embedded in tabs, tabs embedded in navigation? Neither seems like it will do quite what I want. On the other hand, if I stick with a basic navigation app and just add the tabs, aren't I going to have a lot of extra code?

What's the best basic approach for this?

+1  A: 

So far, I'm looking at a UITabBarController with UINavigationControllers in each pane with a little custom code to pop the navigation controller on the target tab back to the root on a tab switch.

Steven Fisher
+1  A: 

I've built apps which do just this. The best way to think about it is to start at the most narrow part, the individual view controllers. In the iPod example, this would include controllers for Artists, Albums, Playlists, Songs, etc. Note if you tap on a playlist, it takes you to a list of songs. These are two separate view controllers.

Each of tabs you see on the iPod app have a Navigation controller in them. The nav controller wraps the root view controllers of the tabs of the app. And then each of the nav controllers are set as the ViewControllers of the tab controller. The code would look something like this

FirstTabViewController *first = [[FirstTabViewController alloc] init...];
SecondTabViewController *second = ...;

UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:first];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:second];

myTabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nil];
// Then make sure to release things to avoid leaks

If you wanted to handle the transition from say, Playlists->List of songs in a selected playlist, you would do this in the Playlist viewcontroller ([self.navigationController pushViewController:theListOfSongsViewController animated:SUREWHYNOT]).

jbrennan
That's a lot of detail. Thanks!
Steven Fisher
A: 

Apple has some great documentation on combining view controllers (navigation controllers inside tab controllers)

http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html

Shannon Cornish