示例代码:
-(void)ConnectWithRequest:(NSMutableURLRequest*)req{
if(![req isEqual:theRequest]){
[req retain];
[theRequest release];
theRequest = req;
}
XMLConnection = [[XMLWebServiceConnection alloc]init];
Connection=[[NSURLConnection alloc]initWithRequest:theRequest delegate:XMLConnection];
}
在XMLConnection类中,我实现了NSURLConnection
委托方法:
-(id)init{
if(self=[super init]){
receivedData = [[NSMutableData alloc]init]; //member of a class
}
return self;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[receivedData release];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSString *theXML = [[NSString alloc] initWithBytes: [receivedData mutableBytes] length:[receivedData length] encoding:NSUTF8StringEncoding];
NSLog(@"\nResponse printed :\n\n\n %@\n",theXML);
[theXML release];
}
当我运行此代码时,
方法:
connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
没有被召唤,出现这种情况的原因是什么?如何解决这个问题??
由于