I'm loading more than 30-50 images, which are stored in document directory. They all images are loaded immediately in collectionView
, but when scroll collectionView
at that time it will stuck.
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"ImageCell";
ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
//Load image from document directory
NSString *imageName = [arrCollection objectAtIndex:indexPath.row];
NSString *imagePath = [NSString stringWithFormat:@"%@/%@",(AppObj).imagefolderPath, imageName];
UIImage *localImg = [[UIImage alloc]initWithContentsOfFile:imagePath];
cell.imgSketch.image = localImg;
cell.txtName.text = [NSString stringWithFormat:@"%@",[imageName stringByReplacingOccurrencesOfString:@".png" withString:@""]];
cell.layer.masksToBounds = YES;
return cell;
}
I also tried following dispatch block
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
UIImage *localImg = [[UIImage alloc]initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",(AppObj).imagefolderPath,[arrCollection objectAtIndex:indexPath.row]]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imgSketch.image = localImg;
});
});
Please suggest me any solution to overcome from this problem.
Thanks in advance