Graphics Programs Reference
In-Depth Information
- (void)fetchEntries
{
// Create a new data container for the stuff that comes back from the service
xmlData = [[NSMutableData alloc] init];
// Construct a URL that will ask the service for what you want -
// note we can concatenate literal strings together on multiple
// lines in this way - this results in a single NSString instance
NSURL *url = [NSURL URLWithString:
@"http://forums.bignerdranch.com/smartfeed.php?"
@"limit=1_DAY&sort_by=standard&feed_type=RSS2.0&feed_style=COMPACT"];
// For Apple's Hot News feed, replace the line above with
// NSURL *url = [NSURL URLWithString:@"http://www.apple.com/pr/feeds/pr.rss"];
// Put that URL into an NSURLRequest
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Create a connection that will exchange this request for data from the URL
connection = [[NSURLConnection alloc] initWithRequest:req
delegate:self
startImmediately:YES];
}
Kick off the exchange whenever the ListViewController is created. In
ListViewController.m , override initWithStyle: .
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self fetchEntries];
}
return self;
}
Build the application to make sure there are no syntax errors.
Collecting XML data
This code, as it stands, will make the connection to the web service and retrieve the last 20
posts. However, there is one problem: you don't see those posts anywhere. You need to
implement delegate methods for NSURLConnection to collect the XML data returned
from this request.
Figure 25.5 NSURLConnection flow chart
Search WWH ::




Custom Search