我有一个简单的 RSS 阅读器。故事被下载,放入 UITableView,当你点击它时,每个故事都会加载到 UIWebView 中。它工作得很好。不过现在,我想在左侧添加一张图片(就像您在 YouTube 应用中看到的那样)。但是,由于我的应用程序是从 RSS 提要中提取的,我不能简单地指定图像 X 出现在 X 行中,因为 X 行明天将是 Y 行,事情会出现问题,你知道吗?我目前正在从YouTube RSS 提要中提取,并且可以获得视频标题、描述、发布日期,但我不知道如何提取提要中的每个条目之外的小缩略图。
正如您可能知道的那样,我是一个编码新手(这是我的第一个应用程序,而不是 Hello World 应用程序),我对自己缺乏知识感到非常沮丧。
谢谢!
顺便说一句,这里有一些示例代码:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
if (currentElement) {
[currentElement release];
currentElement = nil;
}
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
}
}