1

I have tableview that consists of cells of Youtube thumbnails that is retrieved with the help of AFNetworking's setImageWithURL method. So how do I re-use the thumbnails in these cells to another view?

Thanks in advance.

2 Answers2

2

In UIImageView+AFNetworking ,once image downloaded with a url gets cached using AFImageCache (NSCache).

Trick here is use same url to download image but it will not opt for download but provide you cached image.

EDIT : Take a look at this in UIImageView+AFNetworking's setImageWithURLRequest:placeholderImage:success:failure:

UIImage *cachedImage = [[[self class] sharedImageCache] cachedImageForRequest:urlRequest];
if (cachedImage) 
{
  //provide cache image

} 
else 
{
  //download new image from url

}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

You could get a reference the image instance from the UIImageView.

UIImage *imageToReuse = cell.imageView.image

Have a look at the UIImagView documentation.

A better option though would be to use AFNetworking to download the images, put them in a cache, for example using NSCache, and then getting them through it. This seems like a cleaner approach to me then extracting them from the cell. These links might be useful in this regard:

Community
  • 1
  • 1
mokagio
  • 16,391
  • 3
  • 51
  • 58
  • Well, yeah. I did use AFNetworking in the project. It's just that I forgot to highlight it with code tags in my original question so you probably missed it. My bad. The question is, won't I get a different reference of image than the one retrieved from the net if I use your code above? – Bawenang Rukmoko Pardian Putra Feb 09 '15 at 06:11