Graphics Programs Reference
In-Depth Information
@protocol ListViewControllerDelegate
// Classes that conform to this protocol must implement this method:
- (void)listViewController:(ListViewController *)lvc handleObject:(id)object;
@end
First, let's update WebViewController . In WebViewController.h , declare that
this class conforms to ListViewControllerDelegate .
// Must import this file as it is where ListViewControllerDelegate is declared
#import "ListViewController.h"
@interface WebViewController : UIViewController <ListViewControllerDelegate>
@property (nonatomic, readonly) UIWebView *webView;
@end
When one of the rows is tapped in the table view, the ListViewController will send
the listViewController:handleObject: message to the WebViewControl-
ler . The object passed as the argument will be the RSSItem that corresponds to the se-
lected row. In WebViewController.m , implement listViewControl-
ler:handleObject: .
#import "RSSItem.h"
@implementation WebViewController
- (void)listViewController:(ListViewController *)lvc handleObject:(id)object
{
// Cast the passed object to RSSItem
RSSItem *entry = object;
// Make sure that we are really getting a RSSItem
if (![entry isKindOfClass:[RSSItem class]])
return;
// Grab the info from the item and push it into the appropriate views
NSURL *url = [NSURL URLWithString:[entry link]];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[[self webView] loadRequest:req];
[[self navigationItem] setTitle:[entry title]];
}
Notice that the code creating and loading the request is the same code that we are cur-
rently running in ListViewController .
Next, in ListViewController.m , modify the
tableView:didSelectRowAtIndexPath: method to send listViewCon-
troller:handleObject: to the WebViewController .
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (![self splitViewController])
[[self navigationController] pushViewController:webViewController
Search WWH ::




Custom Search