0

I am having a hard time fetching the image from my RSS feed to Xcode. I have been able to get the date, title, even the category. The image is however in the first line of the description, as seen in the RSS feed below:

<item>
<title>Stevie Wonder Tribute</title>
<link>http://celebirious.com/bey/?p=6925</link>
<comments>http://celebirious.com/bey/?p=6925#comments</comments>
<pubDate>February 17, 2015</pubDate>
<dc:creator>
<![CDATA[ Haley ]]>
</dc:creator>
<category>
<![CDATA[ Uncategorized ]]>
</category>
<guid isPermaLink="false">http://celebirious.com/bey/?p=6925</guid>
<description>
<![CDATA[
<img src="http://i2.wp.com/celebirious.com/bey/wp-content/uploads/2015/02/normal_Tribute-004.jpg?fit=1024%2C1024" class="attachment-large wp-post-image" alt="normal_Tribute-004" />Beyonce performed during the Stevie Wonder: Songs In The Key Of Life &#8211; An All-Star GRAMMY Salute held at Nokia Theatre L.A. Live on February 10, 2015. Watch her performance below!
]]>
</description>
[..]
</item>

The XCode looks like this.

@interface APPMasterViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
 NSMutableString *pubDate;
NSMutableString *category;
NSMutableString *link;
NSMutableString *description;
NSString *element;
}

Then I'm using SDWEBImage to try and outsource the image:

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

NSString * imageURL = [[feeds objectAtIndex:indexPath.row] objectForKey: @"description"];

[cell.theimage sd_setImageWithURL:[NSURL URLWithString:imageURL]
               placeholderImage:[UIImage imageNamed:@"candid-02.jpg"]];

return cell;
}

Lastly:

 - (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];
    pubDate  = [[NSMutableString alloc] init];
    category = [[NSMutableString alloc] init];
    description = [[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"];
    [item setObject:pubDate forKey:@"pubDate"];
     [item setObject:category forKey:@"category"];
    [item setObject:description forKey:@"description"];
    [feeds addObject:[item copy]];

}

}

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

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

if ([element isEqualToString:@"pubDate"]) {
    [pubDate appendString:string];
}

if ([element isEqualToString:@"category"]) {
    [category appendString:string];
}


if ([element isEqualToString:@"description"]) {
    [description appendString:string];
}

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

}

I feel like there is something missing, can someone please help?

HalesEnchanted
  • 615
  • 2
  • 9
  • 20

1 Answers1

0

I inserted an enclosure tag instead so I was about to get it working with this: Xcode Get image url from rss feed

Community
  • 1
  • 1
HalesEnchanted
  • 615
  • 2
  • 9
  • 20