views:

94

answers:

1

I am creating application that simply reads data from an XML file and displays it in a table view.

I created a "refresh" button when clicked i want it to redownload the xml file and display it again however it seems to crash my application if there is a XML file already downloaded.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

    ipb = [[IPB alloc] init];
 sectionTitle=[[NSMutableArray alloc]init];

 currentURL=@"http://localhost:8888/xml/Sinnergy.xml";



 [self reloadTableView];

    [window makeKeyAndVisible];
 return YES;
}
-(void)reloadTableView

{ 


 pathURL = [NSURL URLWithString:currentURL];
 parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
 [parser setDelegate:self];
 [parser parse];
 [mainTableView reloadData];

}
A: 

You are leaking the parser, and if its an instance variable it might cause issues. You should go

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
[parser release];

Also you are asking the parser to start parsing, but at that point of time you shouldn't be reloading the table, it should be in your

- (void)parserDidEndDocument:(NSXMLParser *)parser

delegate method. Try that and if it still crashes post the crash report

Rudiger
I actually meant to remove that before posting. That was just something i was toying around with sorry.
Forgoten Dynasty
Works perfect thanks :).
Forgoten Dynasty