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.
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.
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
}
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: