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类都独立工作,因为他们都有自己的工作要完成。 我有一个parseQueue这是NSOperationqueue我已经添加了两个不同的操作。

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方法。

完成解析后,通知主线程解析结束并返回结果。

Sagos

相关问题