Tutorial :Tab/navigation hybrid like iPod/Music



Question:

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?


Solution:1

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]).


Solution:2

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.


Solution:3

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »