Hello all ,
I seem to have a probably newbie problem but here it is. How do I get my dictionary from my parser class , which has building a tree for a drill down table back to my drilldowntabledelegate class. my app looks something like this.
My parser file looks something like this
I've been getting my inspiration and information from the following links
http://www.iphonesdkarticles.com/2009/03/drill-down-table-view-with-detail-view.html
and the xml parsing article.
What works :
1) Building a nice tree which can be read into by my app ( tested it with writetoFile) 2) xmlparsing works ( it's a decent xmlfile )
3) the drilldowntable example
question: how do I get my (build by parser)Tree which has been build by my parser to my drilldowntableappdelegate ?
ps. if this doesn't work can I also build my parser in my delegate file ( i know sloppy but I assume my filled tree will work there )
I seem to have a probably newbie problem but here it is. How do I get my dictionary from my parser class , which has building a tree for a drill down table back to my drilldowntabledelegate class. my app looks something like this.
Code:
@implementation DrillDownAppAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize data;
-(void)StartParser
{
//NSURL *url = [[NSURL alloc] initWithString:@"http://sites.google.com/site/virtuagymtestxml/testxml/Books.xml"];
//NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//local
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [ Path stringByAppendingPathComponent:@"exercises.xml"];
NSData *Data = [[NSData alloc] initWithContentsOfFile:DataPath];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:Data];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success){
NSLog(@"No Errors");
}
else
{
NSLog(@"Error Error Error!!!");
}
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[self startParser];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Tree2.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
//this is what needs to happen
**NSDictionary *tempDict = dictionaryFromMyParser**
self.data = tempDict;
[tempDict release];
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
Code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"exercises"]) {
//init tree
[B] [B]Tree = [NSMutableDictionary new];[/B] //so after this one has been build completely by my parser I want it to return it to my drilldowntableappdelegate file[/B]
Rows = [NSMutableArray new];
[Tree setObject:Rows forKey:@"Rows"];
//Initialize the array.
... all kinds of arrays here
}
if([elementName isEqualToString:@"menu_mob"]) {
amenuMob = [[menuMob alloc]init];
}
if([elementName isEqualToString:@"menuitem"]) {
amenuItem = [[menuItem alloc] init];
amenuItem.IDE = [[attributeDict objectForKey:@"id"] integerValue];
amenuItem.text = [attributeDict objectForKey:@"text"];
NSLog(@"reading id menuitem %i", amenuItem.IDE);
NSLog(@"reading text menuitem %@", amenuItem.text);
[appDelegate.menuitems addObject:amenuItem];
}
http://www.iphonesdkarticles.com/2009/03/drill-down-table-view-with-detail-view.html
and the xml parsing article.
What works :
1) Building a nice tree which can be read into by my app ( tested it with writetoFile) 2) xmlparsing works ( it's a decent xmlfile )
3) the drilldowntable example
question: how do I get my (build by parser)Tree which has been build by my parser to my drilldowntableappdelegate ?
ps. if this doesn't work can I also build my parser in my delegate file ( i know sloppy but I assume my filled tree will work there )