开发者

UITabelView reloaded from NSXMLParser (iphone SDK 4.0)

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开发者_如何学JAVA];
 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];

}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜