0

I am trying to create a gif as a place holder for my SDImageCache.

So first off I created the gif:

    _imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.thumbnailImageView.frame.size.width,
                                                              cell.thumbnailImageView.frame.size.height)];
    _imageView.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00000"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00001"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00002"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00003"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00004"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00005"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00006"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00007"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00008"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00009"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00010"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00011"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00012"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00013"], [UIImage imageNamed:@"Polygon 1 copy.bolt_00014.png"], nil];
    _imageView.animationRepeatCount = 500;

I then turned it into an UIimage

UIImage *imagety = _imageView.image; // get the UIImage
UIImage *otherImage = [UIImage imageNamed:@"Loadimage.png"]; // load another image
_imageView.image = otherImage; // change in the image in your UIImageView

following that I put it as the placeholder:

 SDImageCache *imageCache = [SDImageCache sharedImageCache];
    [imageCache queryDiskCacheForKey:encodedString done:^(UIImage *image, SDImageCacheType cacheType) {

        if (image){
            cell.thumbnailImageView.image = image;
        }else{
            [cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:encodedString] placeholderImage:imagety completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
                [imageCache storeImage:image forKey:encodedString]; 
            }];
        }
    }];

But this does not seem to work? Do you have any ideas why?

maxisme
  • 3,974
  • 9
  • 47
  • 97

1 Answers1

0

If you check the value returned by _imageView.image:

UIImage *imagety = _imageView.image; 

you should see that it is nil. This is due to your using animationImages to handle an animation through the view.

You cannot have a UIImageView (or the animation associated to it) used as a placeholder image in SDImage.

You could use:

UIImage *imagety = [UIImage animatedImageWithImages:
                         [NSArray arrayWithObjects:
                             [UIImage imageNamed:...],
                             nil]
                    duration:10.0f]; 

(docs)

animatedImageWithImages:duration:

Creates and returns an animated image from an existing set of images.

   + (UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration
Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123