I have array of images which contain fullpath of image. I stored images in document directory. The problem is when i scroll down the image load time in collection view is slow so scrolling is also very poor. Referencing this code to make it faster.
But the problem is images not displayed in cell. My collection view code is
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
AlbumImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AlbumImageCell" forIndexPath:indexPath];
cell.albumImage.image=nil;
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"AlbumImageCell" owner:self options:nil] objectAtIndex:0];
}
NSString *path=[documentImage objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:path];
// note that this can be a web url or file url
ImageRequest *request = [[ImageRequest alloc] initWithURL:url];
UIImage *image = [request cachedResult];
if (image) {
UIImageView *imageView = (UIImageView *)[cell viewWithTag:127];
imageView.image = image;
cell.albumImage.image=image;
} else {
[request startWithCompletion:^(UIImage *image, NSError *error) {
if (image && [[collectionView indexPathsForVisibleItems] containsObject:indexPath]) {
[self.album_ImageView reloadItemsAtIndexPaths:@[indexPath]];
}
}];
}
return cell;
}
I got null in UIImage. Please help me to solve this.