This question has been on my mind ever since I started with iOS development: the UINavigationController and the usage of memory.
I see lots of apps like iMail, Find Friends, Notes, etc. where the UINavigationController makes perfect sense. They allow you to drill down two or three levels of hierarchy and that’s it.
But imagine browsing a deep hierarchy, like your Mac’s file system, starting from the root folder.
If I used a UINavigationController, I would keep on pushing hundreds of controllers on the stack (worst case). I don’t consider that a good usage. There can be cases where the pushed controllers can become very heavy (as far as memory is concerned) and they just sit there for nothing.
I would wish there was a “dynamic” version of the UINavigationController: it would just tell you what to create when navigating back up the hierarchy instead of just popping up the hierarchy.
My question is now: is UINavigationController meant to be used for deep hierarchies? What are good alternatives if you want all the animation, bar items, etc?
Or do I see issues where there aren’t any?
UINavigationControlleris dynamic. When you get low on memory, you can release the memory used by parts of the hierarchy that are not visible — this is a manual step when you get a low memory notifiction — and the OS automatically releases the views in the same situation.When the top view controller is popped off the stack, your
viewDidLoadmethod would be called, allowing you to recreate your view.If it really is a problem, iOS5 allows you to create your own “container” views, so you could create your own navigation controller that does exactly as you suggest. Check out the “Implementing a Container View Controller” section of the
UIViewControllerdocumentation.Having said that, you might need to add some shortcuts to work your way around a very deep hierarchy. The UI could get painful if you can only go back one screen at a time.