afnetworking下载图像数组

时间:2014-05-14 14:18:31

标签: ios afnetworking afnetworking-2

我正在尝试下载图像数组,但我从未收到图像回调:

for (int i = 0; i < self.apartments.count; i++) {
        NSLog(@"downloading another image");
        ATProperty *aProp = self.apartments[i];
        if (aProp.aptImages.count > 0) {
            NSURL *url = [NSURL URLWithString:aProp.aptImages[0]];
            NSLog(@"url string: %@", aProp.aptImages[0]);
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            UIImage *placeholderImage = [UIImage imageNamed:@"loading_apt.png"];
            UIImageView *anotherImage;

            NSLog(@"about to start req");
            [anotherImage setImageWithURLRequest:request
                                placeholderImage:placeholderImage
                                         success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
             {
                 NSLog(@"got an IMAGE ");
                 self.imagesArray[i] = image;
                 if (self.apartments[0] == aProp) [self setupDraggableView:image];
             } failure:nil];
        } else {
            UIImage *defImage = [UIImage imageNamed:@"default_apt.png"];
            if (self.apartments[0] == aProp) [self setupDraggableView:defImage];
            [self.imagesArray addObject:defImage];
        }
    }

正如您所看到的,我实际上并不想设置一个imageview,我只是想将UIImage放入一个数组供以后使用。在这种情况下,&#34;得到了一个图像&#34;永远不会收到日志语句。为什么会这样呢?网址有效。此外,这有点像一个JavaScript关闭?例如,如果我在数组中总共有5个公寓,当我进行第一个标注(i = 0)并获得成功回调时,我将是标注实例化的值(即1)?

1 个答案:

答案 0 :(得分:0)

anotherImage是nil,因此它永远不会加载。试试这样:

UIImageView *anotherImage = UIImageView.new;