I touched on this briefly in an earlier post, but a modal view can be useful when you want to display a screen outside the purview of your current navigation controller, like say for an info or help screen:

– (IBAction)showModalView:(id)sender
{
    ModalViewController *modalViewController =
        [[ModalViewController alloc] initWithNibName:NSStringFromClass
        ([ModalViewController class]) bundle:nil];

    UINavigationController *modalViewNavController =
        [[UINavigationController alloc]
        initWithRootViewController:modalViewController];

    [self.navigationController presentModalViewController:
        modalViewNavController animated:YES];

    [modalViewNavController release];
}


Unlike a normal subview, a modal subview needs to be given it’s own navigation controller and not simply pushed onto the current display stack.

To dismiss the modal view, just invoke the following method from within the modal view controller:

– (IBAction)dismissModalView:(id)sender
{
    [self.parentViewController
        dismissModalViewControllerAnimated:YES];
}