Graphics Programs Reference
In-Depth Information
This is because the navigation controller that held the web view controller was only
owned by the split view controller. So when we replaced it with a navigation controller
holding the channel view controller in showInfo: , the first navigation controller was
destroyed. We have to create another navigation controller that holds the web view con-
troller and give it to the split view controller.
In ListViewController.m , modify the
tableView:didSelectRowAtIndexPath: to place a navigation controller with
the WebViewController in the split view controller.
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (![self splitViewController])
[[self navigationController] pushViewController:webViewController
animated:YES];
else {
// We have to create a new navigation controller, as the old one
// was only retained by the split view controller and is now gone
UINavigationController *nav =
[[UINavigationController alloc] initWithRootViewController:webViewController];
NSArray *vcs = [NSArray arrayWithObjects:[self navigationController],
nav,
nil];
[[self splitViewController] setViewControllers:vcs];
// Make the detail view controller the delegate of the split view controller
// - ignore this warning
[[self splitViewController] setDelegate:webViewController];
}
RSSItem *entry = [[channel items] objectAtIndex:[indexPath row]];
[webViewController listViewController:self handleObject:entry];
}
Build and run the application. You should be able to move back and forth between the two
detail view controllers.
The ListViewController doesn't know how to show a post in a web view or show
the info for the RSSChannel . So it delegates those behaviors to other objects.
ListViewController does know about the ListViewControllerDelegate
protocol, and it sends that protocol's message to a conforming detailed view controller to
handle things it can't.
Even though the ListViewController never sets either of the detail view controllers
as its delegate , this is still delegation. Delegation is a design pattern, not a naming con-
Search WWH ::




Custom Search