2009-09-21 222 views
1

我製作了一個簡單的rss閱讀器。該應用程序在數組中加載一個xml原子文件。深入研究rss閱讀器iphone

現在我已經加入分類我的Atom feed,這是第一個數組

在加載哪些是添加編程向下鑽取功能的最佳途徑。 現在只有類別被加載到數組中並顯示。

這是實現代碼

..... 
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]; 
    } 

回答

2

蘋果提供了一個很好的示例應用程序用於展示向下鑽取實現代碼如下:

SimpleDrillDown

+0

非常感謝你。 這就是我正在尋找的。 – bing 2009-09-22 17:29:20

1

編寫一個通用UITableViewController子類,取值數組。然後,當用戶點擊一行時,獲取與所選類別關聯的帖子數組,並將其傳遞給新的視圖控制器。然後,使用[[self navigationController] pushViewController:nextViewController animated:YES];將視圖控制器推入堆棧。