I'm using Parse to store images. I am trying to load the images asynchronously so it does not interfere with the collectionView
scroll. I am new to using dispatch_async
, and am not so sure how to properly implement it. I've also looked into lazy load, but I thought this would work. But it doesn't, and the collectionView
scroll is choppy. Thanks
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
albumImageCell *cell = (albumImageCell *) [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[albumImageCell alloc]init];
}
PFObject *temp = [_dataArray objectAtIndex:indexPath.row];
PFFile *file = [temp objectForKey:@"image"];
if (cell.hasImage == FALSE) {
dispatch_async(imageQueue, ^{
NSData *data = [file getData];
if (data) {
dispatch_async(dispatch_get_main_queue(), ^(void){
cell.imageView.image = [UIImage imageWithData:data];
cell.hasImage = TRUE;
});
}
});
}
return cell;
}