0

Im using UICollectionView for showing listing of images using SDWebImage which is very jerky and the scroll is not smooth. Any suggestions as to how do I proceed with this?

below is code in

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    NSString * cellIdentifier = @"offersCell";

    HotDealsCollectionViewCell * cell = (HotDealsCollectionViewCell *)[self.productsCollectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    cell.layer.shouldRasterize = YES;
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

    cell.layer.shadowColor = [[UIColor colorWithRed:210.0/255.0 green:210.0/255.0 blue:210.0/255.0 alpha:1.0] CGColor];
    cell.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
    cell.layer.shadowRadius = 3.0f;
    cell.layer.shadowOpacity = 1.0f;
    cell.layer.masksToBounds = NO;
    CGRect shadowFrame = cell.layer.bounds;
    CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
    cell.layer.shadowPath = shadowPath;

    cell.backgroundColor = [UIColor whiteColor];

    if ([self.productsArray count] > 0) {
        Product * product = [self.productsArray objectAtIndex:indexPath.item];
        cell.productName.text = product.productName;
        cell.productEndDate.hidden = NO;
        cell.productImageView.clipsToBounds = YES;
        cell.productEndDate.textAlignment = NSTextAlignmentCenter;

           [cell.productImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", product.productImage]] placeholderImage:[UIImage imageNamed:@"noProduct"]];


    }

return cell;
}

3 Answers3

1

Thats due to Image allocation, try the following

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
  cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
  UIImage *image = [[UIImage imageWithCGImage:[list objectAtIndex:indexpath.row] thumbnailImage]];

    dispatch_sync(dispatch_get_main_queue(), ^(void) {
        cell.imageView.image = image;
    });
  });

  return cell;
}
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
0
 if ([[SDWebImageManager sharedManager] diskImageExistsForURL:[NSURL URLWithString:url]]) {

        [self.imageView setImage:[[SDWebImageManager sharedManager].imageCache imageFromDiskCacheForKey:url]];

    } else {
        [self.imageViewsd_setImageWithPreviousCachedImageWithURL:[NSURL URLWithString:url]
                                                        placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                                                                    options:SDWebImageRefreshCached progress:nil
                                                                  completed:nil];
    }
0

try this put below code in custom cell method

- (void)awakeFromNib
{

self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;

self.layer.shadowColor = [[UIColor colorWithRed:210.0/255.0 green:210.0/255.0 blue:210.0/255.0 alpha:1.0] CGColor];
self.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
self.layer.shadowRadius = 3.0f;
self.layer.shadowOpacity = 1.0f;
self.layer.masksToBounds = NO;
CGRect shadowFrame = cell.layer.bounds;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
self.layer.shadowPath = shadowPath;

self.backgroundColor = [UIColor whiteColor];
}

and remove this from -cellForItemAtIndexPath

try this