2011-06-04 35 views
0

NSURLConnection的委託方法不叫。當我使用的是同一類的委託方法在分類頁面NSURLConnection的代表問題

(void) getcategory: (NSString *) catid {
[...]

正確

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

稱爲(didReceiveResponse,connectionDidFinishLoading等)

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlrequest delegate:self]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil]; if(theConnection) { webData = [[NSMutableData data] retain]; } else { NSLog(@"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]; } 
+1

你是什麼意思:「當我使用相同的類委託方法正確調用」? – sergio 2011-06-04 08:22:48

+0

我實現了一個代碼,在同一班級代表正常工作 – Rams 2011-06-04 08:29:53

回答

1

您對2個不同的連接使用相同的請求:theConnection(它是異步的,並且設置了委託 - 連接在您初始化時開始)和[NSURLConnection sendSynchronousRequest: urlrequest returningResponse: &response error: nil];。嘗試刪除第二個