开发者

How to parse xml without freezing GUI in iphone SDK?

开发者 https://www.devze.com 2023-01-19 23:54 出处:网络
How to parse xml without freezing GUI in iphone SDK ? du开发者_StackOverflow社区ring parsing user can interact with gui components. But as i have seen most of the times GUI become freeze when xml par

How to parse xml without freezing GUI in iphone SDK ?

du开发者_StackOverflow社区ring parsing user can interact with gui components. But as i have seen most of the times GUI become freeze when xml parsing performed.


Move parsing to the background thread, the easiest way will be to call:

[someObject performSelectorInBackground:@selector(parse) withObject:nil];

Remember that each thread requires separate NSAutoreleasePool for proper memory management so you will need to create it in the beginning of the parse method and drain in the end:

- (void) parse{
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   ...
   [pool drain];
}


Just as Vladimir mentioned, the background thread is the way to go. Check out the Apple sample code called SeismicXML as it does full asynch XML parsing with the NSXMLParser.

0

精彩评论

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