0

我有标记的 NSURLConnection 子类,需要从多个 URL-s 获取图像数据......这个想法对我来说很清楚,但我无法正确启动连接,因此数据会附加到它的位置...... .在这里我有:

- (IBAction)sophisticatedDownload {
    connectionDict = [[NSMutableDictionary dictionaryWithCapacity:news.count] retain];
    for (int i =0; i<news.count; i++) 
    {
          //init the tagged connection

             if (theConnection) {
                    self.imageData = [NSMutableData data];
                    [connectionDict setObject: imageData forKey: theConnection.connID];    
            } else {       
                    NSLog(@"Connection failed");
            }
    }
}


- (void)connection :(tagConnection *)connection didReceiveData:(NSData *)data {
[[connectionDict objectForKey:connection.connID] appendData:data];
}


- (void)connectionDidFinishLoading:(tagConnection *)connection {

NSLog(connection.connID); 

什么应该

4

1 回答 1

0

你可以像这样开始你的连接 -

NSString *urlString = [NSString stringWithFormat:@"http://EnterYourURLHere"];
NSURL *URL = [NSURL URLWithString:urlString];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]init];
[urlRequest setURL:URL];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];

NSURLConnection *urlConnection = [[NSURLConnection alloc]initWithRequest:urlRequest delegate:self];
if(!urlConnection)
{
    [[[UIAlertView alloc]initWithTitle:@"OOoopppssS !!" message:@"There is an error occured. Please check your internet connection or try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}

但这不是下载多个图像的好方法。请参阅NSURLConnection 下载多个图像以下载多个图像。

于 2012-09-29T16:56:02.047 回答