首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在用MWFeedParser解析的提要中查看图像

在用MWFeedParser解析的提要中查看图像
EN

Stack Overflow用户
提问于 2013-06-22 08:36:30
回答 1查看 691关注 0票数 0

我正在使用MWFeedParser在我的应用程序中下载提要。到目前为止,它运行良好-然而,我无法解析每一篇文章为它的图像URL。这是我目前的代码:

代码语言:javascript
复制
// MWFeedItem.h

NSData* firstImg;
@property (nonatomic, retain) NSData* firstImg;
MWFeedItem.m
add synthesize and dealoc
代码语言:javascript
复制
// RootViewController.m

- (NSString *)getFirstImage:(NSString *)htmlString{

NSScanner *theScanner;
NSString *text = nil;

theScanner = [NSScanner scannerWithString: htmlString];

// find start of tag
[theScanner scanUpToString: @"<img src=\"" intoString: NULL];
if ([theScanner isAtEnd] == NO) {
    NSInteger newLoc = [theScanner scanLocation] + 10;
    [theScanner setScanLocation: newLoc];

    // find end of tag
    [theScanner scanUpToString: @"\"" intoString: &text];
}

return text;
}

(void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);    

NSString* str_imageUrl = [self getFirstImage:item.summary];    

item.firstImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:str_imageUrl]];     

if (item) [parsedItems addObject:item];      
}

我不能用这段代码查看图像,我也不知道为什么。

EN

回答 1

Stack Overflow用户

发布于 2013-06-28 15:04:47

试试CXFeedParser。它是从MWFeedParser分叉的,并包含一个NSArray图像为每个feedItem。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17248841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档