Presented View Controller

The chief purpose of view controllers is to make views come and go coherently in the interface. The simplest way of making a view come and go is through a presented view controller. Most often, the view that comes and goes will be fullscreen; while present, it will take over the entire interface. (On the iPhone, this is always the case.)

There is a temptation to think of a presented view controller as secondary or temporary. This is often true, but such a conception misses the full power of a presented view controller, which is, quite simply, that it changes the interface. A presented view controller’s view may have a complex interface; it might have child view controllers (Figure 19-6); it might present yet another view controller; it might take over the interface permanently. You, the programmer, may be conscious that the presented view controller’s view is in some sense covering the previous interface; but the user might or might not experience the interface that way.

For example, in Apple’s Music app, the two alternating views that appear when you view the currently playing song are equal partners (Figure 19-7); there’s no implication that one is secondary to the other. Yet it’s likely that one of them (probably the second one) is a presented view controller.

Two views that are equal partners
Figure 19-7. Two views that are equal partners

To make a view controller present another view controller, ...

Get Programming iOS 6, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.