Reputation: 3187
I was wondering what is the best practice for this very common action: Say i have a collection view, and each cell of this collection view has an imageView that receives a url for an image.
The images are large, so i want to preload all the images in advance (or say 5 in advance). I'm using AFNetworking imageView Category.
So here's what i did - creating a temp UIImageView and set the url to it each iteration, but it seems not to be working right. (the images still takes time to show up, while i want it to be instantly, and if i close the internet connection, the images do not load from cache).
- (void)preloadGalleryImages {
for (GalleryItem *item in _galleryItems) {
UIImageView *tempImageView = [[UIImageView alloc] init];
[tempImageView setImageWithURL:item.imageURL placeholderImage:IMAGE(@"placegolder")];
}
}
}
Thanks,
Upvotes: 2
Views: 724
Reputation: 1561
There is a universal way of preheating images in collection views that was implemented in one of the Apple PhotosKit samples. You can anticipate user actions and fetch images that might soon appear on the display (that are close to the viewport). This feature is implemented in Nuke and DFImageManager.
Upvotes: 1