开发者

NSURLConnection Delegates problem

NSURLConnection delegate method is not called (didReceiveResponse,connectionDidFinishLoading etc) .when i am using a same class delegate methods called properly

category *cat = [[category alloc]init];  
    [cat getcategory:@"1088"]; 

in a category page

(void) getcategory: (NSString *) catid {

[...]

 NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlrequest delegate:self];  

        NSHTTPURLResponse *response;  
       [NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil];   

        if( theConnection )  
        {  
            webData = [[NSMutableData data] retain];  
        }  
        else  
        {  
            N开发者_如何转开发SLog(@"theConnection is NULL");  
        }  

    }  

    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {   
        [webData setLength: 0];  
    }  
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data  
    {  
        [webData appendData:data];  
    }  
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {  
        NSLog(@"ERROR with theConenction");  
        [connection release];  
        [webData release];  
    }  
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {  
        NSLog(@"DONE. Received Bytes: %d", [webData length]);  
        NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:  [webData length] encoding:NSUTF8StringEncoding];  
    }


you're using the same request into 2 different connections: theConnection (which is asynchronous and with delegate set up - the connections starts when you init it) and [NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil];. Try removing the second

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜