【问题标题】:iPhone RSS thumbnailiPhone RSS 缩略图
【发布时间】:2010-10-10 17:39:39
【问题描述】:

我有一个简单的 RSS 阅读器。故事被下载,放入一个 UITableView,当你点击它时,每个故事都会加载到一个 UIWebView 中。它工作得很好。不过现在,我想在左侧添加一张图片(就像您在 YouTube 应用中看到的那样)。但是,由于我的应用程序是从 RSS 提要中提取的,我不能简单地指定图像 X 出现在 X 行中,因为 X 行明天将是 Y 行,并且事情会出现问题,你知道吗?我目前正在从YouTube RSS 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];
    }

}

【问题讨论】:

    标签: iphone rss sdk parsing thumbnails


    【解决方案1】:

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

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

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

    希望对你有帮助

    【讨论】:

    • 嗯。我看到的最简单的方法是在 parserDidStart 中使用 attributeDict,因为这就是我所有其余代码的设置方式。任何人都可以帮我提取media:thumbnail的URL属性的代码吗?开发文档:preview.tinyurl.com/cmhzch YouTube API:preview.tinyurl.com/az7tek
    【解决方案2】:

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

    将此视为您的 youtube 供稿,

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

    你会得到一个带有 media:thumbnail 标签的 xml,你可以用它来显示 youtube 的缩略图。

    希望对你有帮助!!!

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2013-07-24
        • 2017-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-15
        • 1970-01-01
        相关资源
        最近更新 更多