0

试图解析两个具有 XML 数据的不同 URL。

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 数据并希望有并发操作。但是当第二个操作完成加入队列时,它仍然会查看第一个类操作。我迷失了,因为我不知道为什么即使在发布后它仍在寻找头等舱。任何人都可以提出一些想法并帮助我。

4

1 回答 1

0

我想出了答案。

需要在各自的类中调用每个 XML URL,并为每个调用单独调用 NSOperation。无需调用应用程序委托方法,而是根据需要调用 viewdidload 或 viewdidappear 方法。

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

萨戈斯

于 2011-03-02T20:02:38.913 回答