0

I can use the SDWebImage to load a small size image with an url to show on an UIImageView. But I don't know how to load a larger size image with another url to show on the same UIImageView after I has loaded the smaller size image.

[aImageView setImageWithURL:fristUrl placeholderImage:[UIImage imageNamed:@"placeholder.png"] success:^(UIImage *image) {
    [aImageView setImageWithURL:secondUrl placeholderImage:image success:^(UIImage *image) {
        ;
    } failure:^(NSError *error) {
        NSLog(@"error105size:%@", [error description]);
    }];
} failure:^(NSError *error) {
    NSLog(@"error50size:%@", [error description]);
}];

I has used the code above, but it crashed. Hope your answers.

Aevit
  • 21
  • 5

3 Answers3

0

Check out Developer.Apple example LazyTableImages

Please read ReadMe.txt for more details

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102
0

Actually, you don't need to create any hidden UIImageView to do the trick.

What you must do is set the first URL (with the smaller image) to be directly downloaded into your UIImageView, and then use SDWebImageManager to download the larger version on the background. When it finishes download, simply set the downloaded image in your image view.

Here's how you can do that:

// First let the smaller image download naturally
[self.imageView setImageWithURL:self.imageURL];

// Slowly download the larger version of the image
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:self.currentPhoto.largeImageURL options:SDWebImageLowPriority progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
    if (image) {
        [self.imageView setImage:image];
    }
}];

Note how I used SDWebImageLowPriority option. This way, the image (which should be naturally larger than the first one) will be downloaded in a low priority and should not cancel the first download.

Gui Moura
  • 1,360
  • 1
  • 16
  • 26
0
UIButton *btn = [[UIButton alloc] init];
[btn sd_setImageWithURL:[NSURL URLWithString:obj.thumbnail_pic] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"photoDefault.png"] options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    NSLog(@"img samll download ok:%@",obj.thumbnail_pic);
    if (image) {
         [btn sd_setImageWithURL: [NSURL URLWithString:[ctl getBigImg:obj.thumbnail_pic]] forState:UIControlStateNormal
                placeholderImage:image];
    }
}];
Gank
  • 4,507
  • 4
  • 49
  • 45