解析XML时,iPhone应用程序会冻结

时间:2010-01-25 22:13:00

标签: iphone nsxmlparser nsthread nsautoreleasepool

每当我解析XML Feed时,我的应用都会冻结。

我试过改为调用它:

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

调用:

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

但是我的应用程序因此变得非常不稳定... iPhone模拟器刚刚崩溃而没有错误警告。

1 个答案:

答案 0 :(得分:2)

而不是打电话:

[NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];
你应该致电:

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

您的UI处于冻结状态,因为您在UI线程中进行了漫长的操作。