0

XML 데이터가있는 두 개의 서로 다른 URL을 구문 분석하려고합니다.NSOperationQueue를 사용하여 두 개의 다른 NSOperation 클래스를 구문 분석해야합니다.

static NSString *string1 = @"http://abc.com/abc1.xml"; 
NSURLRequest *URL1 =[NSURLRequest requestWithURL:[NSURL URLWithString:string1]]; 
self.URL1Connection =[[[NSURLConnection alloc] initWithRequest:URL1 delegate:self] autorelease]; 

static NSString *string2 = @"http://abc.com/abc2.xml"; 
NSURLRequest *URL2 =[NSURLRequest requestWithURL:[NSURL URLWithString:string2]]; 

self.URL2Connection =[[[NSURLConnection alloc] initWithRequest:URL2 delegate:self] autorelease]; 

둘 다 서로 다른 NSOperation 클래스가 독립적으로 작동하므로 둘 다 자체 작업을 완료해야합니다. 두 개의 다른 작업을 추가 한 NSOperationqueue parseQueue 있습니다.

TestOperation *testOperation = [[TestOperation alloc]              
    initWithData:self.data1 delegate:self ]; 

    [self.parseQueue addOperation:testOperation]; 
    [testOperation release]; // once added to the NSOperationQueue it's retained, we don't need it anymore 
    testOperation = nil; 

    Test1Operation *test1Operation = [[Test1Operation alloc]   
    initWithData:self.data2]; 

[self.parseQueue addOperation:test1Operation]; 
    [test1Operation release]; // once added to the NSOperationQueue it's retained, we don't need it anymore 
    test1Operation = nil; 

기본적으로 두 개의 XML 데이터를 별도로 구문 분석하려고하며 동시 작업을 수행하려고합니다. 그러나 두 번째 작업이 대기열에 추가되는 과정을 지나면 여전히 첫 번째 클래스 작업을 살펴 ​​봅니다. 나는 왜 그것이 아직도 첫 번째 클래스를 찾고있는 후에도 잘 모르는 이래로 길을 잃었다. 아무도 아이디어를 포기하고 나를 도울 수 있습니까?

답변

0

나는 대답을 알아 냈다.

각각의 클래스에서 각 XML URL을 호출하고 각 호출마다 NSOperation을 별도로 호출해야합니다. 응용 프로그램 대리자 메서드를 호출하는 대신 필요에 따라 viewdidload 또는 viewdidappear 메서드를 호출하십시오.

구문 분석이 끝나면 주 스레드에 구문 분석이 끝났음을 알리고 결과를 반환합니다.

사고 스

관련 문제