1

我有一个简单的 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];
    }

}
4

3 回答 3

1

我建议尝试使用TouchXML进行 xml 解析。我发现它更容易使用。

像获取任何其他文本字段一样获取图像的 url。然后,当您创建对象并将其添加到故事中时,请执行以下操作:

currentImage = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString: theUrl]]]

希望这可以帮助

于 2009-03-02T12:20:27.043 回答
0

我会使用NSScanner从提要项中扫描您的网址并获取 youtube 视频 ID。然后我会使用视频 ID 从 URL 获取缩略图。您可以从这里的答案中选择您想要的缩略图 URL:https ://stackoverflow.com/a/2068371/1484168

于 2013-06-19T23:22:48.890 回答
0

有同样的问题,但通过 Youtube API 的引用解决了,

将此视为您的 youtube 提要,

http://gdata.youtube.com/feeds/base/users/[插入用户名]/uploads

您将在其中获得带有 media:thumbnail 标签的 xml,您可以使用它来显示 youtube 的缩略图。

希望对你有帮助!!!

于 2010-11-03T11:36:13.820 回答