2009-09-21 8 views
1

J'ai fait un simple lecteur rss. L'application charge un fichier atom xml dans un tableau.Drill down lecteur rss iphone

Maintenant, j'ai ajouté des catégories à mon flux d'atomes, qui sont d'abord chargés dans le tableau

Quelle est la meilleure façon d'ajouter des fonctionnalités drill down programme. Maintenant, seules les catégories sont chargées dans la matrice et affichées.

C'est le code de mise en œuvre

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

Répondre

2

Apple propose une application bon exemple pour démontrer un tableview drill-down:

SimpleDrillDown

+0

Merci beaucoup. C'est ce que je cherchais. – bing

1

Ecrire un UITableViewController générique sous-classe qui prend un tableau de valeurs . Ensuite, lorsque l'utilisateur appuie sur une ligne, récupérez le tableau de messages associé à la catégorie sélectionnée et transmettez-le à un nouveau contrôleur de vue. Ensuite, poussez le contrôleur de vue sur la pile en utilisant [[self navigationController] pushViewController:nextViewController animated:YES];.

1

Je viens de sortir un open source RSS/Atom Parser for iPhone et j'espère que cela pourrait être utile.

Je serais ravi d'entendre vos pensées à ce sujet aussi!