views:

17

answers:

1

Hi! I've been very unfortunate with my programming. I am still rather new to Objective-C, but I am trying to learn as quickly as possible.

I need to complete an RSS Reader for iPhones application, a relatively simple one which parses the rss feed, displays it in a navigation-table view and when you click on an article you are taken to a main page.

Unfortunately, I am having difficulty with the parsing aspect. Currently, the program downloads all the articles, but I would like to display it in lists of 10, along with a next button at the bottom. Once the next button is clicked, the parsing continues and the next 10 are on display.

I am sorry but I cannot show you the code I am using at the moment as I am on my home computer and the project is on the office mac. If anyone could give me some Ideas i would be most grateful. I have tried a number of methods (making an additional array to act as an article counter so I could record which article is which for which list, for example) but i keep running into roadblocks as I just dont know how to use the program well enough to do that.

Please, I am in a lot of need! Thank you.

A: 

(This is me again) I am sorry if this is rather vague, but I believe I can give sample code. I am trying to make it that the program pauses parsing after 10 articles are parsed, displays those 10, then continues parsing and displaying another 10 if a next button is pressed.

In the parser.m, i have written:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];

if ([elementName isEqualToString:@"item"]) {
    item = [[NSMutableDictionary alloc] init];
    self.currentTitle = [[NSMutableString alloc] init];
    self.currentDate = [[NSMutableString alloc] init];
    self.currentSummary = [[NSMutableString alloc] init];
    self.currentLink = [[NSMutableString alloc] init];
    self.currentImage = [[NSMutableString alloc] init];
}//IF END
//podcast url is an attribute of the element enclosure
if ([currentElement isEqualToString:@"enclosure"]) {
    [currentImage appendString:[attributeDict objectForKey:@"url"]];
    NSLog(@"Image = %@", currentImage);
}//IF END
else if([currentElement isEqualToString:@"img"]){
    [currentImage appendString:[attributeDict objectForKey:@"src"]];
    NSLog(@"Image = %@", currentImage);
}//ELSE IF END

}

I also have the didEndElement and Found characters section:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName{

if ([elementName isEqualToString:@"item"]) {
    [item setObject:self.currentTitle forKey:@"title"];
    [item setObject:self.currentLink forKey:@"link"];
    [item setObject:self.currentSummary forKey:@"summary"];
    [item setObject:self.currentImage forKey:@"image"];


// Parse date here
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setDateFormat:@"EEE, d MMM yyyy"]; // Thu, 18 Jun 2010 04:48:09 -0700
    NSLog(@"FC date1 = %@", self.currentDate);
    NSDate *date = [[NSDate alloc] init]; 
    date = [dateFormatter dateFromString:currentDate];
    NSLog(@"FC date2 = %@", date);

    [item setObject:self.currentDate forKey:@"date"];
    //[item setObject:date forKey:@"date"];
    [date release];
    [items addObject:[item copy]];
    NSLog(@"Item details = %@", items);

    [count addObject:[item objectForKey:@"title"]];
    NSLog(@"count = %@", count);
}//IF END

}

I have also been having some issues with formatting the date, but thats a minor issue.

also:

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

if ([currentElement isEqualToString:@"title"]) {
    [self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
    [self.currentLink appendString:string];
} else if ([currentElement isEqualToString:@"image"]) {
    [self.currentImage appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
    [self.currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
    [self.currentDate appendString:string];
    NSCharacterSet* charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@" \n"];
    [self.currentDate setString: [self.currentDate stringByTrimmingCharactersInSet: charsToTrim]];
}//IF-ELSE-IF END

}

I would be most grateful if someone could give me a tip on what to do to pause the program...or allow me to parse in groups of 10...I am at a loss ;_;

Thank you for your time.

SKato