iPhone RSS 缩略图

发布于 2024-07-14 07:36:20 字数 2606 浏览 4 评论 0原文

我有一个简单的 RSS 阅读器。 故事被下载,放入 UITableView 中,当您单击它时,每个故事都会加载到 UIWebView 中。 效果很好。 不过现在,我想在左侧添加一个图像(就像您在 YouTube 应用程序中看到的那样)。 但是,由于我的应用程序从 RSS 提要中提取数据,因此我不能简单地指定图像 X 出现在 X 行中,因为 X 行明天将成为 Y 行,事情会变得混乱,你知道吗? 我目前正在从 YouTube RSS feed,并且可以获取视频标题、描述、发布日期,但我不知道如何在 feed 中的每个条目旁边提取小缩略图。

正如您可能知道的那样,我是一名编码新手(这是我除 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];
    }

}

I have a simple RSS reader. Stories are downloaded, put into a UITableView, and when you click it, each story loads in a UIWebView. It works great. Now though, I'd like to incorporate an image on the left side (like you'd see in the YouTube app). However, since my app pulls from an RSS feed, I can't simply specify image X to appear in row X because row X will be row Y tomorrow, and things will get out of order, you know? I am currently pulling from a YouTube RSS feed, and can get the video title, description, publication date, but I'm stuck as to how to pull the little thumbnail besides each entry in the feed.

As you can probably tell, I'm a coding newbie (this being my first application other than a Hello World app) and I'm getting so frustrated by my own lack of knowledge.

Thanks!

BTW, here's some sample code:

- (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];
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

許願樹丅啲祈禱 2024-07-21 07:36:20

我建议尝试 TouchXML 进行 xml 解析。 我发现合作起来容易多了。

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

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

希望这有帮助

I would recommend trying out TouchXML for xml parsing. I find it a lot easier to work with.

Fetch the url for the image like you fetch any other text field. Then when you create the object and add it to the story do something like:

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

Hope this helps

余厌 2024-07-21 07:36:20

有同样的问题,但通过 Youtube API 的参考解决了,

将其视为您的 YouTube feed,

http://gdata.youtube.com/feeds/base/users/[insert UserName]/uploads

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

希望它能帮助你!

Have the same problem,but solved with references from Youtube API,

consider this as u r youtube feed,

http://gdata.youtube.com/feeds/base/users/[insert UserName]/uploads

where u will get a xml with media:thumbnail tag which u can used to display thumbnail images of youtube.

Hope it will help u !!!

烧了回忆取暖 2024-07-21 07:36:20

我将使用 NSScanner 扫描 feed 项中的 url 并获取 youtube 视频 ID。 然后我将使用视频 ID 从 URL 获取缩略图。 您可以从此答案中选择所需的缩略图网址:https://stackoverflow.com/a/2068371/1484168

I would use NSScanner to scan your url from the feed item and get the youtube video id. Then I would then use the video ID to get the thumbnail image from a URL. You can pick which thumbnail URL you want from this answer here:https://stackoverflow.com/a/2068371/1484168

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文