0

단일보기 컨트롤러 클래스에서 두 개의 연결을 만들고 싶습니다. 이 목적으로 NSOperationQueue를 사용하고 있습니다. 두 개의 연결이 두 개의 함수로 만들어지고 큐 내부를 밀어 넣습니다. 문제는 대리자가 호출되지 않는다는 것입니다. 제발 도와주세요. 사전비동기 연결이 호출되지 않음

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSOperationQueue *queue=[[NSOperationQueue alloc] init]; 
    NSInvocationOperation *invOperation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(createConnection1) object:nil]; 
    NSInvocationOperation *invOperation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(createConnection2) object:nil]; 
    NSArray *ops=[[NSArray alloc] initWithObjects:invOperation1,invOperation2,nil]; 
    [queue addOperations:ops waitUntilFinished:YES]; 

} 


-(void) createConnection1{ 

    //create connection 
    NSLog(@"Create Connection 1"); 
    url1 =[[NSMutableString alloc] initWithFormat:@"http://www.google.com/ig/api?weather=New Delhi"]; 

    NSURLRequest *theRequest1=[NSURLRequest requestWithURL:[NSURL URLWithString:url1] 
               cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:60.0]; 
    theConnection1=[[NSURLConnection alloc] initWithRequest:theRequest1 delegate:self]; 
    if (theConnection1) { 
     connectionCreated1=YES; 
     receivedData1 = [[NSMutableData data] retain]; 
     NSLog(@"received data 1 %@",receivedData1); 
     //[theConnection1 setDelegate:self]; 
    } 
} 

-(void) createConnection2{ 
    //create connection 
    NSLog(@"Create Connection 2"); 
    url2 =[[NSMutableString alloc] initWithFormat:@"http://www.google.com/ig/api?weather=Chennai"]; 

    NSURLRequest *theRequest2=[NSURLRequest requestWithURL:[NSURL URLWithString:url2] 
               cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:60.0]; 
    theConnection2=[[NSURLConnection alloc] initWithRequest:theRequest2 delegate:self]; 
    if (theConnection2) { 
     connectionCreated2=YES; 
     receivedData2 = [[NSMutableData data] retain]; 
     //[theConnection2 setDelegate:self]; 
     NSLog(@"received data 2 %@",receivedData2); 
    } 

} 


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    if (connectionCreated1==YES) { 
     [receivedData1 setLength:0]; 
    } 
    else if (connectionCreated2==YES) { 
     [receivedData2 setLength:0]; 
    } 
    else { 
     NSLog(@"did not receive response"); 
    } 


} 
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{ 

    if (connectionCreated1==YES) { 
    [theConnection1 release]; 
    xmlParser1 = [[NSXMLParser alloc] initWithData:receivedData1]; 
     [xmlParser1 setDelegate:self]; 
    [xmlParser1 parse]; 
    } 
    else if(connectionCreated2==YES){ 
     [theConnection2 release]; 
     xmlParser2 = [[NSXMLParser alloc] initWithData:receivedData2]; 
     [xmlParser2 setDelegate:self]; 
     [xmlParser2 parse]; 

    } 



} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"connection failed" message:@"" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    if (connectionCreated1==YES) { 
     [receivedData1 appendData:data]; 
    } 
    else if(connectionCreated2==YES) { 
     [receivedData2 appendData:data]; 
    } 
    else { 
     NSLog(@"data not received"); 
    } 

} 
+0

제발 나를 도와주세요. 나는 큰 문제가있다 –

답변

0

첫 번째 링크에서 준 URL 감사 당신은 뉴 델리 사이의 공간이 ... ... borken 일이 "http://www.google.com/ig/api?weather=New Delhi"보는 것 같다. 대신 사용해보십시오 http://www.google.com/ig/api?weather=New+Delhi

+0

두 링크가 브라우저에서 작동하지만 아무도 xcode에서 데이터를 반환하지 않습니다. 즉, 아무도 대표자를 부르지 않습니다. –

관련 문제