I am currently connecting to a database that then gets a bunch of xml that I parse with NSXMLParser (as shown below) Once this is done I would like to pass the array data to another method to sort it and then seperate the array into sections (this is so my uitableview Index will work). And finally displayed in my tableview.
My Main question is how (where in the code) can I pass my data array over to the method I have created.
#pragma mark - Parsing lifecycle
- (void)startTheParsingProcess:(NSData *)parserData
{
[myDataArray release]; // clears array for next time it is used.
myDataArray = [[NSMutableArray alloc] init]; //initalizes the array, this is a must have!!!! :)
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process
[parser setDelegate:self];
[parser parse]; //Starts the event-driven parsing operation.
[parser release];
//[self.tableView reloadData]; // this reloads the data in the tabel view once the nsmutablearray has been filled with values
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"item"]) {
// NSLog(@"Found title!");
itemString = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[itemString appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqual:@"item"]) {
//NSLog(@"ended title: %@", itemString);
[myDataArray addObject:itemString]; //this is where i pass the values over to my array.
//TODO: Test release on memory consumption etc
[itemString release];
itemString = nil;
}
}
//method to sort array and split for use with uitableview Index
- (IBAction)startSortingTheArray:(NSMutableArray *)arrayData
{
}
Implement didEndDocument delegate method for your NSXMLParser,
if your – (IBAction)startSortingTheArray:(NSMutableArray *)arrayData return type is non IBAction, lets say its return type is void the following should work fine. I don’t know what happens when you pass arrayData to IBAction return type method.