Adding a Modal View

Modal views are great for those situations when you want the user (or the user wants) to do something outside the application flow. Rather than use a Navigation controller with a Back button, you display a Modal view with controls that allow the user to either select an action or cancel the procedure. (Much of the work in adding the Destination controller to the storyboard spelled out in the steps list in the previous section has to do with enabling the user to either select a destination in the Table view or to press Cancel to leave things as they are.)

The usual way to manage Modal views is by creating a protocol that’s adopted by the controller presenting the Modal view. The Modal view, when the user has selected an action or Cancel, calls the presenting controller’s delegate method. The requesting controller then dismisses the Modal controller. Using this approach means that, before it dismisses the Modal controller, the presenting controller can get any data it needs.

You start implementing the Modal view by declaring the protocol and a few other properties you’ll need, as well as the protocols the Destination Controller needs to adopt.

To get things started, add the bolded code in Listing 20-1 to Destination Controller.h.

Listing 20-1: Updating the Destination Interface

#import <UIKit/UIKit.h>

@protocol DestinationControllerDelegate;

@interface DestinationController : UIViewController

<UITableViewDelegate, UITableViewDataSource>

@property (weak, ...

Get iPad Application Development For Dummies, 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.