开发者

iPhone app freezes when parsing XML

开发者 https://www.devze.com 2022-12-18 13:47 出处:网络
My app freezes whenever I parse an 开发者_运维技巧XML feed. I have tried calling this instead: [NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];

My app freezes whenever I parse an 开发者_运维技巧XML feed.

I have tried calling this instead:

[NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];

which calls:

-(void) parseXML {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [self parseXMLFileAtURL:path];
    [pool drain]; 
}

but my app has become quite unstable as a result...the iPhone Simulator just crashed with no error warning.


Rather than calling :

[NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];

you should call :

[self performSelectorInBackground:@selector(parseXML) withObject:nil]

Your UI is freezing because you are doing lengthy operations in UI Thread.

0

精彩评论

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

关注公众号