我想创建一个类来处理其他类的所有 HTTP 连接工作(以避免重复编写代码)。我称它为 ConnectionCenter(NSObject 的子类)并向其添加以下代码:
-(void)connect:(NSString *)strURL obj:(ConnectCenter *)objConnect
{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:strURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:objConnect];
if (theConnection)
{
// receivedData is declared as a method instance elsewhere
receivedData = [[NSMutableData data] retain];
}
else
{
// inform the user that the download could not be made
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
}
其他类通过传递 URL 和 ConnectionCenter 对象来调用它。但是没有调用 ConnectionCenter 中的方法“didReceiveData”。关于它有什么问题的任何想法?