Graphics Programs Reference
In-Depth Information
currentString = [[NSMutableString alloc] init];
[self setTitle:currentString];
}
else if ([elementName isEqual:@"description"]) {
currentString = [[NSMutableString alloc] init];
[self setInfoString:currentString];
}
}
Note that
currentString
points at the same object as the appropriate instance variable
Figure 25.9 Two variables pointing at the same object
This means that when you append characters to the
currentString
, you are also ap-
pending them to the
title
or to the
infoString
.
In
RSSChannel.m
, implement the
parser:foundCharacters:
method.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)str
{
[currentString appendString:str];
}
When the parser finds the end of the
channel
element, the channel object will return
control of the parser to the
ListViewController
. Implement this method in
RSSChannel.m
.
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
// If we were in an element that we were collecting the string for,
// this appropriately releases our hold on it and the permanent ivar keeps
// ownership of it. If we weren't parsing such an element, currentString
// is nil already.
currentString = nil;
// If the element that ended was the channel, give up control to