O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modal Views

The simplest form of view controller containment is a modal view. Here, a view controller replaces its entire view with another view controller’s view. This is done by sending the first view controller the presentModalViewController:animated: message, handing it the second view controller. The first view controller now contains the second. The second view controller becomes the first view controller’s modalViewController; the first view controller is the second view controller’s parentViewController. This state of affairs persists until dismissModalViewControllerAnimated: is called; it is implemented by the parent view controller (which knows which view controller to dismiss because that is its modalViewController), but may be sent to the modal view controller (whose default behavior is to pass the message on to its parentViewController).

The second view, the modal view, is often thought of as temporary or secondary, as somehow covering the parent view which is the real view; it’s as if the second view were merely waiting to be dismissed, thus revealing the real view once again. This is indeed frequently the case, but this conception doesn’t quite capture the power of modal views. In particular:

  • A modal view might not be temporary or secondary; it might appear every bit as primary as the parent view, and it might never be dismissed.
  • A modal view’s controller can itself be of any degree of complexity. For example, it might be a UITabBarController with many tab bar items ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required