4

I want to set a thumbnail image url and high res image url so that first thumbnail image is downloaded and then the high res image is downloaded

Rajat Talwar
  • 11,922
  • 1
  • 18
  • 12

3 Answers3

7

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
  • I don't see why not. Just make sure you cancel the requests after a cell gets out of bounds, so you don't end up reusing that cell later – Gui Moura Jun 27 '17 at 23:38
3

It's late but i solved my problem with following code

UIImageView * hiddenImageView = [[UIImageView alloc] init];

[hiddenImageView sd_setImageWithURL:thumbUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

    if (image) {

        mImageView.image = image;
    }

    if (originalUrl != nil) {

        [mImageView sd_setImageWithURL:originalUrl placeholderImage:image completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){

            if (image) {

                mImageView.image = image; // optional
            }

        }];

    }
}];
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
1

Download to a hidden UIImageView somewhere on the view, and then switch between the two when its done loading, via:

[cell.imageView setImageWithURL:[NSURL     
URLWithString:@"http://www.domain.com/path/to/image.jpg"]
   placeholderImage:[UIImage imageNamed:@"placeholder.png"]
   completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}];
Rob R.
  • 3,629
  • 2
  • 14
  • 12