Search code examples
ioscocoa-touchuinavigationcontrollerpushviewcontrollerpresentmodalviewcontroller

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 ?


Solution

  • 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"?