Ios 如何通过RSS源从网站获取图像?

Ios 如何通过RSS源从网站获取图像?,ios,image,uiimageview,rss,nsxmlparser,Ios,Image,Uiimageview,Rss,Nsxmlparser,我目前正在构建一个iOS RSS提要应用程序,它将有一个显示提要的表视图。我希望在每个表视图单元格中放置一个ImageView,该图像将来自该RSS源的网站。我目前正在文件中使用NSXMLParserDelegate。我只需要知道如何从网站上获取图像。。。这里只是我正在使用的rss提要的一个示例。是否可以从此URL获取图像?谢谢你的帮助!这是到目前为止我的代码。我需要添加什么才能获得图像 #import "JSSSecondViewController.h" #import "JSSDetail

我目前正在构建一个iOS RSS提要应用程序,它将有一个显示提要的表视图。我希望在每个表视图单元格中放置一个ImageView,该图像将来自该RSS源的网站。我目前正在文件中使用NSXMLParserDelegate。我只需要知道如何从网站上获取图像。。。这里只是我正在使用的rss提要的一个示例。是否可以从此URL获取图像?谢谢你的帮助!这是到目前为止我的代码。我需要添加什么才能获得图像

#import "JSSSecondViewController.h"
#import "JSSDetailViewController.h"
#import "JSSFirstViewController.h"

@interface JSSSecondViewController () {
    NSXMLParser *parser;
    NSMutableArray *feeds;
    NSMutableDictionary *item;
    NSMutableString *title;
    NSMutableString *link;
    NSString *element;
}

@end

@implementation JSSSecondViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    feeds = [[NSMutableArray alloc] init];
    NSURL *url = [NSURL URLWithString:@"http://rss.cnn.com/rss/cnn_tech.rss"];
    parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return feeds.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
    return cell;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

    element = elementName;

    if ([element isEqualToString:@"item"]) {

        item    = [[NSMutableDictionary alloc] init];
        title   = [[NSMutableString alloc] init];
        link    = [[NSMutableString alloc] init];

    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"item"]) {

        [item setObject:title forKey:@"title"];
        [item setObject:link forKey:@"link"];

        [feeds addObject:[item copy]];

    }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

    if ([element isEqualToString:@"title"]) {
        [title appendString:string];
    } else if ([element isEqualToString:@"link"]) {
        [link appendString:string];
    }

}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

    [self.tableView2 reloadData];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {

        NSIndexPath *indexPath = [self.tableView2 indexPathForSelectedRow];
        NSString *string = [feeds[indexPath.row] objectForKey: @"link"];
        [[segue destinationViewController] setUrl:string];

    }
}



@end
这是我将要分析的XML

<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>CNET Gaming</title>
<link>http://www.cnet.com/#ftag=CADa872701</link>
<description>
Game on! Get the latest in gaming news, video game reviews, computer games & video game consoles.
</description>
<language>en</language>
<pubDate>Thu, 10 Apr 2014 23:23:50 GMT</pubDate>
<lastBuildDate>Thu, 10 Apr 2014 23:23:50 GMT</lastBuildDate>
<ttl>2</ttl>
<image>
<title>CNET Gaming</title>
<url>
http://i.i.cbsi.com/cnwk.1d/i/ne/gr/prtnr/CNET_Logo_150.gif
</url>
<link>http://www.cnet.com/#ftag=CADa872701</link>
</image>
<item>
<title>
Get a Moga Mobile Gaming System for Android for $13 shipped
</title>
<link>
http://www.cnet.com/news/get-a-moga-mobile-gaming-system-for-android-for-13-shipped/#ftag=CADa872701
</link>
<description>
This Bluetooth game controller sold for $49.99 when it debuted last year.<img width='1' height='1' src='http://cnet.com.feedsportal.com/c/34938/f/645455/s/38e7da50/sc/5/mf.gif' border='0'/><br clear='all'/><br/><br/><a href="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/1/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/1/rc.img" border="0"/></a><br/><a href="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/2/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/2/rc.img" border="0"/></a><br/><a href="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/3/rc.htm" rel="nofollow"><img src="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/rc/3/rc.img" border="0"/></a><br/><br/><a href="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/a2.htm"><img src="http://da.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/a2.img" border="0"/></a><img width="1" height="1" src="http://pi.feedsportal.com/r/193360522992/u/191/f/645455/c/34938/s/38e7da50/sc/5/a2t.img" border="0"/>
</description>
<pubDate>Thu, 10 Apr 2014 23:21:10 GMT</pubDate>
<guid>
http://www.cnet.com/news/get-a-moga-mobile-gaming-system-for-android-for-13-shipped/#ftag=CADa872701
</guid>
<dc:creator>Rick Broida</dc:creator>
<media:thumbnail url="http://cnet3.cbsistatic.com/hub/i/r/2014/04/02/0eeab98d-efb9-4779-a973-7b709f4fbb06/thumbnail/300x230/c7edbbac37a02b874a7bcfe373f6f9ec/moga-mobile.jpg"/>
</item>
<item>
<title>Xbox boss: Microsoft won't sell us off</title>
<link>
http://www.cnet.com/news/xbox-boss-microsoft-wont-sell-us-off/#ftag=CADa872701
</link>

网络游戏
http://www.cnet.com/#ftag=CADa872701
游戏开始!获取游戏新闻、视频游戏评论、电脑游戏和视频游戏控制台的最新信息。
EN
2014年4月10日星期四23:23:50 GMT
2014年4月10日星期四23:23:50 GMT
2.
网络游戏
http://i.i.cbsi.com/cnwk.1d/i/ne/gr/prtnr/CNET_Logo_150.gif
http://www.cnet.com/#ftag=CADa872701
以13美元的价格购买一款适用于Android的Moga移动游戏系统
http://www.cnet.com/news/get-a-moga-mobile-gaming-system-for-android-for-13-shipped/#ftag=CADa872701
这款蓝牙游戏控制器去年上市时售价为49.99美元。








2014年4月10日星期四23:21:10 GMT http://www.cnet.com/news/get-a-moga-mobile-gaming-system-for-android-for-13-shipped/#ftag=CADa872701 布罗伊达 Xbox老板:微软不会出卖我们 http://www.cnet.com/news/xbox-boss-microsoft-wont-sell-us-off/#ftag=CADa872701

这只是一个片段。它包含对图像的引用。在这种情况下,如何在tableView中显示图像?

RSS源的XML是否包含图像URL?你的问题没有提供任何细节来提供真正的帮助,你的问题表明你在寻找解决方案方面几乎没有努力。你有什么?你试过什么?你到底需要什么帮助?@rmaddy我已经编辑了这个问题……在你的问题中加入一些你试图解析的相关XML会有所帮助。不要让别人做太多的研究。问题应该是自包含的。好的,谢谢您的更正@rmaddyy您需要解析
url
标记并获取url。然后请求该URL的数据,并从该
NSData
创建
UIImage