O'Reilly logo

Learning iPhone Programming by Alasdair Allan

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 View Controllers

So far in this chapter we’ve looked at two of Apple’s application templates. However, in this section we’re going to focus once again on an individual view controller—or rather, a way to present a view controller to the user. After table views and the UINavigationController it’s probably one of the most heavily used ways to present data: it’s the modal view controller.

You’ll have seen a modal controller in action many times when using your iPhone. A view slides in from the bottom of the screen and is usually dismissed with a Done button at the top of the screen. When dismissed, it slides back down the screen, disappearing at the bottom.

In the main controller we would generally have a button or other UI element; tapping this would trigger an event linked to the following method in the view controller, which would bring up the modal view:

-(void)openNewController:(id)sender {
    OtherController *other = [[OtherController alloc] init];1
    [self presentModalViewController:other animated:YES];2
    [other release];3
}
1

We instantiate the view controller that manages the view we wish ...

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