2010-10-15 63 views

回答

3

移动解析到后台线程,最简单的方法是调用:

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

请记住,每个线程都需要单独的NSAutoreleasePool进行适当的内存管理,所以你需要在分析的开始创建方法和漏:

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

但是我有一些复杂的情况,如: – Matrix 2010-10-15 16:50:55

+0

[self performSelectorInBackground:@selector(CustomMethod :) withObject:nil]; (void)CustomMethod:(id)sender { \t NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; \t ObjXMLWebService = [[XMLWebService的alloc] initWithSoapElements:[NSDictionary的dictionaryWithObjectsAndKeys:@ “值”,@ “密钥”,零] BodyTitle:@ “TitleOfXMLWebService” BodyAction:URLValue的xsi:URLValue XSD:URLValue皂:URLValue版本: VersionNumber编码:EncodingUsed]; ObjXMLWebService.theRequest = [ObjXMLWebService ConfigureRequestWithContentType:ContentTypeValue SOAPAction:SoapActionValue To:URLValue]; – Matrix 2010-10-15 16:59:20

+0

[ObjXMLWebService ConnectWithRequest:ObjXMLWebService.theRequest]; \t \t [pool drain]; } - (无效)ConnectWithRequest:(NSMutableURLRequest *)REQ { ...... ...... 连接= [[NSURLConnection的页头] initWithRequest:theRequest委托:XMLConnection]; XMLConnection定义连接委托方法,它还调用/设置另一个类来解析委托方法。 – Matrix 2010-10-15 17:01:44

0

正如弗拉基米尔提到的,后台线程是要走的路。查看名为SeismicXML的Apple示例代码,因为它使用NSXMLParser完全异步XML解析。