Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - pushViewController vs presentModalViewController difference

What is the difference beetween calling presentModalViewController and pushViewController, when :

  • animation is set to NO (even if yes, that's just an animation style that can be changed).
  • a navigation controller is defined when presenting the modal view, so it can be navigable too, with a call stack, ....

Is this just to be able to go back from the first pushed view ? Woooaaaaaa.....

I guess the difference is elsewhere and deeper. No ?

like image 533
Oliver Avatar asked Nov 08 '11 00:11

Oliver


2 Answers

Ignoring transitions/animations and how things are structured behind the scenes (which aleph_null's alswer provides a good discussion of), the only user-facing difference is the ability to return to the preceding view automatically using the navigation bar.

If you use pushViewController you will automatically get a "Back" button in the navigation bar. If you use presentModalViewController you do not, and generally will have to implement your own controls and/or callbacks to handle dismissing the controller.

Conceptually the modal presentation style is generally used for atomic tasks that you cannot navigate away from (i.e. you either complete the task, or you cancel, and you cannot do anything else within the app until you do one or the other).

If you're wondering why have the difference in the first place, I can't say. Personally I think frameworks that provide a unified API for moving from one controller to another (like cocos2d, or Android) make a lot more sense.

like image 160
aroth Avatar answered Nov 14 '22 22:11

aroth


The most important difference is about semantics. Modal view controllers typically indicate that the user has to provide some information or do something. This link explains it more in depth: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

Here's another, less abstract difference they talk about:

"When you present a modal view controller, the system creates a parent-child relationship between the view controller that did the presenting and the view controller that was presented. Specifically, the view controller that did the presenting updates its modalViewController property to point to its presented (child) view controller. Similarly, the presented view controller updates its parentViewController property to point back to the view controller that presented it."

Also see this thread: why "present modal view controller"?

like image 31
aleph_null Avatar answered Nov 14 '22 22:11

aleph_null