-2

Anyway to handle or display UIImage with caching and with placeholder?

I have found one answer from stack exchange but it didnot work for me given below the link :

Best way to cache images on ios app?

Notes: I dont have any URL because i get image object of PHIMAGE asset library.

Community
  • 1
  • 1
SmarterSusheel
  • 169
  • 2
  • 15

3 Answers3

0

You can use SDWebImage
It is very simple to display and cache image.

[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.image_url.com"]
                  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
0

You can use a very usefull library called SDWebImage

SDWebImage automagically cache all your images when you provide a valid URL with the sd_setImageWithURL. So the next time you call it, will use the cache system instead of re-download the image.

Example to implement in a UIImageView from their github:

// Here we use the new provided sd_setImageWithURL: method to load the web image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
brunobasas
  • 383
  • 2
  • 14
0

There was a problem of smoothing an all image while scroll the table but there is an issue of reload the cell not the caching problem i solved this issue.

I get an image one by one from local identifier which is provided by PHAsset framework and display that image into cell.

For reference Code:

PHFetchResult *savedAssets = [PHAsset fetchAssetsWithLocalIdentifiers:@[your local identifier] options:nil]; [savedAssets enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {

        //this gets called for every asset from its localIdentifier you saved
        PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
        imageRequestOptions.synchronous = YES;
        imageRequestOptions.deliveryMode = PHImageRequestOptionsResizeModeFast;

        [[PHImageManager defaultManager]requestImageForAsset:asset targetSize:CGSizeMake(50,50) contentMode:PHImageContentModeAspectFill options:imageRequestOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
            NSLog(@"You get an image from result");

        }];
    }];
SmarterSusheel
  • 169
  • 2
  • 15