When you present a modal view controller, the system creates a relationship between the view controller that did the presenting and the view controller that was presented. Specifically, the view controller that did the presenting updates its presentedViewController property to point to its presented view controller. Similarly, the presented view controller updates its presentingViewController property to point back to the view controller that presented it. Figure 10-1 shows the relationship between the view controller managing the main screen in the Calendar app and the presented view controller used to create new events.
Dismissing a view controller dismisses not only that view controller but also any view controllers it presented.
If you need to present a view controller programmatically, you must do the following:
- (void)add:(id)sender {
|
// Create the root view controller for the navigation controller
|
// The new view controller configures a Cancel and Done button for the
|
// navigation bar.
|
RecipeAddViewController *addController = [[RecipeAddViewController alloc]
|
init];
|
|
// Configure the RecipeAddViewController. In this case, it reports any
|
// changes to a custom delegate object.
|
addController.delegate = self;
|
// Create the navigation controller and present it.
|
UINavigationController *navigationController = [[UINavigationController alloc]
|
initWithRootViewController:addController];
|
[self presentViewController:navigationController animated:YES completion: nil];
|
} |