iphone - How to notify ViewController on parse end with multiple ViewControllers using a single parser -


I have created an RSS parser and 3 table view and RSS files parses correctly but I do not know how parsing When finished, TableViewController has ended, so it can update the view. TableViewController parser and parse a feed

  parser = [[RSSParser alloc] initWithURL: @ "http://randomfeed.com"].  

I can use single feed items such as

  [parser feed items];  

Representatives of NSXMLParser in parser.mi methods applied to:

  - (void) parser: (NSXMLParser *) parser didStartElement: (NSString * ) ElementName NamespaceURI: (NSString *) NamespaceURI QualifiedName: (NSString *) QualifiedName attributes: (NSDictionary *) AttributeDict - (void) parser: (NSXMLParser *) parser foundCharacters: (NSString *) string - (void) parser: ( NSXMLParser *) parser didEndElement: (NSString *) elementName - (minus) parserDidEndDocument: (NSXMLParser *) parser  

c, then I how parserDidEndDocument to inform my controllers I add tableview data TE get.

Cheers from the beginning of an obj-c.

The exact delegation is widely used in the Cocoa framework.

The data should be a protocol to file parsing, which like any callbacks, the class must implement the methods of the protocol:

  // XMLParser .h // Import Statements here .. Protocol XMLParserDelegate - (zero) parserDidFinish: (NSArray *) theParsedData; // as many ways as you do, didFail, tax progression etc. @ @ @ Explorer XMLParser: NSObject {ID & lt; XMLParserDelegate & gt; Representative; // We do not know what type of object it will be, only that it will follow the XMLParserDelegate Protocol} @ property (assign) id representative; // methods @end  

In the implementation of XMLParser:

  @implementation XMLParser @ synthesis representative; - (void) ParsedDead Document: (NSXMPP * *) Parser Delegate parserdishfish: dataiylected array]; // This is where it happens}  

Then in your controller interface file you say that you have XMLParserDelegate Protocol.

  // MyController.h #import "must comply with XMLParser.h" @Interface: UIViewController & lt; XMLParserDelegate & gt; {// This is where you "promise" to implement protocol methods. }  

The MyController.m file is now in the instance of XMLParser

  @implementation MyController -. (Zero) init {XMLParser * parser = [[XMLParser Alloc] init]; [Parser set Deliaget: Self] // Now parser is in reference to this object. [Parsing start]; } - (zero) parserfishfish: (NSArray *) result {// Now you have your results in the controller, it can be set as table view and call table data source of View.reloadData; }  

This is a great pattern that connects the caller and responder, without knowing something, which the protocol tells about each other.

If I have a visual element that is limited to its functionality, like, say, one clock will have a clock viui controller and it will use hand, dial, etc. They will all be connected to the clock and the clock controller will inform about their actions using this method. Thus, I can use clock arm or dial in other codes, unless they follow the ClockArmDelegate protocol immediately.

Hope it makes sense :) It is, I'm pretty sure, the most used patterns in cocoa.


Comments