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
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 ...