views:

158

answers:

3

Can anyone suggest an article or perhaps an example of how to create an "infinite drill-down" with UINavigationController like you see in the Facebook, IMDB and BrightKite apps?

A: 

Never having done this... I would approach this by keeping a stack with a light-weight object containing the contents of the previous view (perhaps just a URL?). Rather than just push on a new UIViewController to the UINavigationController, you would pop your current one, without animation, then push on the new view. However, I don't think this would properly handle the nice animation.

Another way that comes to mind would be to manipulation the viewControllers array of UINavigationController. After pushing on a new view, just remove the previous view from the array. That way the UINavigationController stack would only ever be 1 or two elements deep. Handling the back button would create the proper view, insert it into the viewControllers array, then pop off the current one. Your state would be managed by the lightweight object stack, not heavyweight view controllers.

-dan

Daniel Blezek
I'm currently looking into using Three20's TTNavigator as a solution, as it appears to support this functionality... though the documentation is terrible so I'm not sure yet.
E-Madd
+3  A: 

The UINavigationController is designed to be used this way. If memory becomes an issue, the nav controller will release hidden views and reload them when the time comes to navigate back down the stack. Apple recommends you load your UIViews from a NIB for this reason.

http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html#//apple_ref/doc/uid/TP40007457-CH103-SW28

Scroll down to item #4, "Configure the view for your root view controller."

kubi
kubi, Thanks for the tip. Have you tried this? You could put a log in viewDidUnload (or isn't this called?).-dan
Daniel Blezek
Based on my experiments, this is not true. UINavigationController does not appear to automatically remove any views from the stack, except when you are navigating back.
E-Madd
@Daniel actually no, but i've also not had memory issues when using NavControllers this way, so I assumed everything was working like the documents described. Please let me now if you find differently.
kubi
A: 

You might find this article useful - it even contains a working xcode project.

Irene