views:

44

answers:

3

Why do Navigation Applications use pushViewController instead of presentModalViewController like all the other apps? How can a Navigation Application be modified to use presentModalViewController instead? Would it be sub-optimal to do so? Why?

+1  A: 

Navigation view controllers and modal view controllers are there for different purposes. The first is used for display hierarchical nested contents. While you request more detailed info about an item, you go deeper in the hierarch pushing more detailed views over the stack.

The modal view is there for displaing only one view over the current. Its usefull for stuff like an info button for your app.

Ricardo de Cillo
I can go deeper than one view using a modal view.
awakeFromNib
but it doesnt mean you should
Ricardo de Cillo
Is there a reason you shouldn't?
awakeFromNib
If you want your view to have a kind of close button in a way that users are confortable with the interface, you are gonna have to create a navigation controller to be pushed modally and a UIBarButtonItem to go in its bar. So, every time you go deeper pushing a view controller modally on top of each other, you have to create a "dummy" UINavigationController just to hold a button. That sounds like a weird situation. It sounds like you are using the fact that every view controller can hold a modal to create a stack that is already implemented by navigation controller. Thats why you shouldn do it
Ricardo de Cillo
+1  A: 

Your question is a little bit like asking why UISplitViewControllers use two controllers and lay their views out side-by-side. That is, UINavigationControllers use pushViewController: to manage their stack of UIViewController instances because that's how Apple decided UINavigationControllers should work. When animated into view, pushed views will slide in from the right and old views slide in from the left when a view is popped.

ANY instance of a UIViewController can use presentModalViewController to display the view of another UIViewController over top of it's own view in a manner which prevents the user from interacting with the view underneath. Depending on the device (iPhone, iPad) you have various options for the visual appearance of the newly presented view and the animation used to bring it into view.

There's nothing stopping you from writing an application that just keeps having one view bring up the next view using presentModalViewController but there'd be no reason to use a UINavigationController to do so. I've never checked if there was a meaningful difference in memory consumption or any other thing you could measure to judge whether doing so is "sub-optimal" from a technical perspective, but it's certainly not the norm so might be sub-optimal from the user experience perspective. Whether that is true or not for your app depends on whether users seem to think the interaction makes sense to them.

imaginaryboy
A: 

Navigation view controllers uses the concept of Stack.Your navigation is stored in stack that's why you can push & pop the View which shows that you can use them for the detail view ....making a hierarchy of views

whereas modal view controllers shows only one view at a time......this is generally used for new flow in app.

Ajay Sharma