2013-02-19 102 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