Drill down rss reader iphone

Posted by bing on Stack Overflow See other posts from Stack Overflow or by bing
Published on 2009-09-21T17:45:20Z Indexed on 2010/05/15 19:54 UTC
Read the original article Hit count: 258

Filed under:
|

Hi everyone, I have made a simple rss reader. The app loads an xml atom file in an array.

Now I have added categories to my atom feed, which are first loaded in the array

What is the best way to add drill down functionality programmatically. Now only the categories are loaded into the array and displayed.

This is the implementation code

.....
loading xml file <snip>
.....

    - (void)parserDidStartDocument:(NSXMLParser *)parser {
        NSLog(@"found file and started parsing");
    }

    - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
        NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]];
        NSLog(@"error parsing XML: %@", errorString);

        UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
    }

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
        //NSLog(@"found this element: %@", elementName);
        currentElement = [elementName copy];

        if ([elementName isEqualToString:@"entry"]) {
        	// clear out our story item caches...
        	Categoryentry = [[NSMutableDictionary alloc] init];
        	currentID = [[NSMutableString alloc] init];
        	currentTitle = [[NSMutableString alloc] init];
        	currentSummary = [[NSMutableString alloc] init];
        	currentContent = [[NSMutableString alloc] init];
        }
    }

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

        //NSLog(@"ended element: %@", elementName);
        if ([elementName isEqualToString:@"entry"]) {
        	// save values to an entry, then store that item into the array...
        	[Categoryentry setObject:currentTitle forKey:@"title"];
        	[Categoryentry setObject:currentID forKey:@"id"];
        	[Categoryentry setObject:currentSummary forKey:@"summary"];
        	[Categoryentry setObject:currentContent forKey:@"content"];

        	[categories addObject:[Categoryentry copy]];
        	NSLog(@"adding category: %@", 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:@"id"]) {
        	[currentID appendString:string];
        } else if ([currentElement isEqualToString:@"summary"]) {
        	[currentSummary appendString:string];
        } else if ([currentElement isEqualToString:@"content"]) {
        	[currentContent appendString:string];
        }
    }

    - (void)parserDidEndDocument:(NSXMLParser *)parser {

        [activityIndicator stopAnimating];
        [activityIndicator removeFromSuperview];

        NSLog(@"all done!");
        NSLog(@"categories array has %d entries", [categories count]);
        [newsTable reloadData];
    }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c