-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to prefetch images the first time? #83
Comments
Not sure if this is the best way to go about this, but I solved it by creating a preload method that basically just loads the image to a dummy UIImageView. Works like a charm. ( I believe you need to use the same HNKCacheFormat when you load it for real. ) + (void)preloadImage:(NSString *)imagePath
{
NSLog(@"Pre-loading image %@", imagePath.lastPathComponent);
UIImageView *imageView = [[UIImageView alloc] init];
HNKCacheFormat *format = [HNKCache sharedCache].formats[@"cacheImageFormat"];
if (!format)
{
format = [[HNKCacheFormat alloc] initWithName:@"cacheImageFormat"];
format.size = CGSizeMake(1024, 768);
format.scaleMode = HNKScaleModeNone;
format.compressionQuality = 1;
format.diskCapacity = 10000 * 1024 * 1024;
format.preloadPolicy = HNKPreloadPolicyAll;
}
[imageView setHnk_cacheFormat:format];
if([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
[imageView hnk_setImageFromFile:imagePath];
}
} |
Thank you for your reply. Your post was very inspiring and I did exactly what you suggested. |
I used this way to make sure a rather big local image would get loaded on the next UIViewController immediately rather than have a slight (but annoying) delay once the UIViewController appeared. Didn't try it for remote images though, too bad it didn't work :( |
I take it back. It works!!! The mistake I made was, setting the cache too small.
It simply ran out of cache space, hence it acted unreliably. I think I need to play with it and find a sensible number. Thank you so much for your help!! |
Alright! Glad I could help :) |
Is this really the best/proper way to do this? |
SDWebImage does already something like that:
Is there something like this in Haneke?
The text was updated successfully, but these errors were encountered: