2010-10-15 68 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解析。