我有一个简单的RSS阅读器。下载故事,放入UITableView,当您单击它时,每个故事都会加载到UIWebView中。它很棒。现在,我想在左侧添加图像(就像你在YouTube应用中看到的那样)。但是,由于我的应用程序来自RSS提要,我不能简单地指定图像X出现在第X行,因为第X行明天将是Y行,而且事情会发生故障,你知道吗?我目前正在从YouTube RSS feed开始,可以获得视频标题,说明,发布日期,但我仍然坚持如何在Feed中的每个条目之外拉小缩略图。
你可能会说,我是一个编码新手(这是我的第一个应用程序,而不是Hello World应用程序),我对自己缺乏知识感到非常沮丧。
谢谢!
BTW,这是一些示例代码:
- (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];
}
}
答案 0 :(得分:1)
我建议尝试TouchXML进行xml解析。我觉得使用它要容易得多。
获取图像的网址,就像获取任何其他文本字段一样。然后,当您创建对象并将其添加到故事时,请执行以下操作:
currentImage = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString: theUrl]]]
希望这有帮助
答案 1 :(得分:0)
遇到同样的问题,但是使用Youtube API的参考资料解决了这个问题,
将此视为youtube Feed,
http://gdata.youtube.com/feeds/base/users/ [insert UserName] / uploads
你将获得带有media:thumbnail标签的xml,你可以用它来显示youtube的缩略图。
希望它能帮助你!!!
答案 2 :(得分:0)
我会使用NSScanner
从Feed项中扫描您的网址并获取YouTube视频ID。然后我会使用视频ID从URL获取缩略图。您可以在此处从此答案中选择所需的缩略图网址:https://stackoverflow.com/a/2068371/1484168