views:

1139

answers:

4

I have a simple RSS reader. Stories are downloaded, put into a UITableView, and when you click it, each story loads in a UIWebView. It works great. Now though, I'd like to incorporate an image on the left side (like you'd see in the YouTube app). However, since my app pulls from an RSS feed, I can't simply specify image X to appear in row X because row X will be row Y tomorrow, and things will get out of order, you know? I am currently pulling from a YouTube RSS feed, and can get the video title, description, publication date, but I'm stuck as to how to pull the little thumbnail besides each entry in the feed.

As you can probably tell, I'm a coding newbie (this being my first application other than a Hello World app) and I'm getting so frustrated by my own lack of knowledge.

Thanks!

BTW, here's some sample code:

- (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  A: 

I would recommend trying out TouchXML for xml parsing. I find it a lot easier to work with.

Fetch the url for the image like you fetch any other text field. Then when you create the object and add it to the story do something like:

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

Hope this helps

bjartek
Hmm. The easiest way I see is to use attributeDict in parserDidStart because that's how all of the rest of my code is setup. Could anyone help me with the code to extract the URL attribute of media:thumbnail? Dev Docs: http://preview.tinyurl.com/cmhzchYouTube API: http://preview.tinyurl.com/az7tek
A: 

How's this coming along?

Clifton Burt
This should not be an answer, but a comment on the question itself.
Kevin Elliott
A: 

Hi! I have the same problem. Did You find out how it works? Thanks!