I have created a RSS parser and 3 TableViews and it parses the RSS files fine but I don’t know how to notify the TableViewController when parsing has ended so it can update the view.
The TableViewController initiates the parser and the parsing of a feed.
parser = [[RSSParser alloc] initWithURL:@"http://randomfeed.com"];
I can access the single feed items like
[parser feedItems];
In parser.m i have implemented the delegate methods of NSXMLParser:
- (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
- (void)parserDidEndDocument:(NSXMLParser *)parser
So how do i get parserDidEndDocument to notify my controllers so i can add the data to the tableview.
Cheers from a obj-c beginner.
Ok the delegation pattern is widely used in the Cocoa framework.
The file that parses data must have a protocol, anyone wanting callbacks form this
Class must implement the methods from the protocol:
In the implementation of the XMLParser:
So in your controllers interface file you says that you will adhere to the XMLParserDelegate protocol.
In the MyController.m file you now instantiate the XMLParser.
This is a great pattern that loosely couples the caller and responder without having them know anything other that what the protocol dictates, about each other.
If I have a view element that is confined to its own functionality, like, say, a clock.
I would have a ClockViewController and it would instantiate arm, dials, etc. They would all be linked to the clock and alert the clock controller about their actions using this pattern. This way I can use the clock arm or dial in other code as I please, as long as the object instantiating them adheres to the ClockArmDelegate protocol.
Hope it makes sense:) it is the, Im pretty sure, most used pattern in Cocoa.