2009-03-02 8 views
1

私は単純なRSSリーダーを持っています。ストーリーがダウンロードされ、UITableViewに入れられ、それをクリックすると、各ストーリーがUIWebViewに読み込まれます。それは素晴らしい作品です。さて、私はあなたのYouTubeアプリに表示されるように、左側に画像を組み込みたいと思います。しかし、私のアプリはRSSフィードからプルするので、行Xは行Xに明示的に指定することはできません。なぜなら、行Xは明日の行Yになり、物事が乱れるからです。私は現在YouTube RSS feedから引っ張っていて、ビデオタイトル、説明、出版日を得ることができますが、フィードの各エントリの他に小さなサムネイルを引っ張る方法については固まっています。iPhone RSSサムネイル

私はコーディング初心者です(これは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]; 
    } 

} 

答えて

1

私はXML解析用TouchXMLを試してみることをお勧めします。私はそれを扱う方がずっと簡単です。

他のテキストフィールドを取得するようなイメージのURLを取得します。あなたがオブジェクトを作成し、物語のような何かにそれを追加するときに:

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

を希望これは

+0

Hmm。私が見ている最も簡単な方法は、それが他のすべてのコードがどのようにセットアップされているかのために、parserDidStartでattributeDictを使用することです。誰でもメディアのURL属性(サムネイル)を抽出するコードを教えてもらえますか? Devドキュメント:http://preview.tinyurl.com/cmhzch YouTube API:http://preview.tinyurl.com/az7tek –

0

を助け、同じ問題を持っていますが、YouTubeのAPIからの参照を解決し、

は、このように考えますウルユーチューブフィード、

http://gdata.youtube.com/feeds/base/users/[insertユーザー名] /アップロードuはメディアを使用してXMLを取得します

:あなたがYouTubeのサムネイル画像を表示するために使用できるサムネイルタグ。

希望すると助かります!

0

私はNSScannerを使用して、フィードアイテムからあなたのURLをスキャンし、YouTube動画IDを取得します。次に、URLからサムネイル画像を取得するためにビデオIDを使用します。この回答からサムネイルURLを選択することができます:https://stackoverflow.com/a/2068371/1484168

関連する問題