2013-02-19 110 views
1

我有一张带照片标题en url的RSS订阅源,并且我想在这些照片中构建。做这个的最好方式是什么?我使用MWPhotoBrowser和插入照片的方式是:带有RSS的iOS照片查看器

self.photos = [NSMutableArray array]; 
[photos addObject:[MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]]]; 
[photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3629/3339128908_7aecabc34b.jpg"]]]; 
[photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3590/3329114220_5fbc5bc92b.jpg"]]]; 

如何使用RSS完成此操作?

谢谢!

回答

1

如果您想从RSS源创建照片查看器,我会建议您调查MWFeedParser。您可以轻松获取每个项目的标题和URL,然后根据需要显示它们。

1 - 使用MWFeedParser,解析您的饲料:

//feedURL would be your Photo RSS Feed 
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL]; 

2 - 在MWFeedParser委托方法didParseFeedItem,加入该项目的链接到你的照片阵列:

-(void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item{ 
    if (item) [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:item.link]]]; 
} 

现在的照片阵列包含您的所有MWPhoto,随心所欲地做任何事情!

+0

请参阅我的编辑 – 2013-02-19 18:29:05

+0

我会做的是使用MWFeedParser抓取RSS源中的所有链接,并将链接放入NSMutableArray。然后,对于该阵列中的每个URL,将一个对象添加到照片数组中:'[photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:URL]]];' – JMarsh 2013-02-19 18:36:52

+0

aha!你有一个示例代码? – 2013-02-19 18:39:58