0

我绝对是个菜鸟,我真的需要你的帮助。我已经在寻找一个一周的解决方案,但我真的不知道该怎么做。我正在尝试从 Web 服务下载一些图标(png 图像),并且我已经在其他地方使用过代码,但仅适用于 1 个图像,而不适用于多个图像。在这种情况下,我应该下载 15 张图片。在这两种情况下,使用 AFImageRequestOperation 或 NSURLConnection sendAsynchronousRequest,我到达了所有 15 个图像的末尾,但之后它以一个我真的不知道如何修复的错误开始,因为它不应该出现在那里!( *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFArray CGPointValue]:无法识别的选择器已发送到实例)。如果我使用 synchronousRequest 下载 15 个图像,则完全没有问题。我做错了什么?是我的错在这里还是其他地方?非常感谢。

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imagePath]];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessing``Block:nil                                                                                            success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
         // Save Image
        [images_icon addObject:image ];
        if ([images_icon count]==[allIcons count]) {
            [self saveAllImagesToDisk];
        }
        }
        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
          NSLog(@"%@", [error localizedDescription]);
          UIAlertView* allerta=[[UIAlertView alloc] initWithTitle:@"Attention"
                    message:@"Some problems here.."
                    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
          [allerta show];
        }];
    [operation start];

NSURL *url = [NSURL URLWithString:percorsoImmagine];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {NSLog(@"lungh %d, error=%@ mime=%@",[data length], error, response.MIMEType);
         if ([data length] > 0 && error == nil && ([response.MIMEType isEqualToString:@"image/png"] || [response.MIMEType isEqualToString:@"image/jpeg"])){
             [images_icon addObject:data ];
             if ([images_icon count]==[allIcons count]) {
                [self saveAllImagesToDisk];
             }
         }
     }];
4

1 回答 1

1

当您使用时,AFImageRequestOperation您将UIImages 添加到,images_icon但是当您使用时,NSURLConnection您将NSDatas 添加到images_icon. 我们需要[self saveAllImagesToDisk]进一步调查。

于 2013-02-23T18:05:21.037 回答