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]; }
你是什麼意思:「當我使用相同的類委託方法正確調用」? – sergio 2011-06-04 08:22:48
我實現了一個代碼,在同一班級代表正常工作 – Rams 2011-06-04 08:29:53