0

im使用UICollectionView为表示使用SDWebImage这是非常干和滚动不平稳的图像的列表。有关如何继续操作的任何建议?的iOS:UICollectionView小区负荷是非常干

下面

- (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; 
} 
+0

cell.layer.shouldRasterize = YES; cell.layer.rasterizationScale = [UIScreen mainScreen] .scale; http://stackoverflow.com/questions/16454160/uicollectionview-has-slow-jerky-loading-of-images-and-scrolling –

+0

请发表您的'cellForItemAtIndexPath'代码。 – iPeter

+0

@MuhammadRaheelMateen我试过这个..但它没有工作.. – user3355310

回答

1

那代码由于图片分配,尝试以下

-(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; 
} 
+0

嗨murtuza,是什么类型的[list objectAtIndex:indexpath.row] – user3355310

+0

其列表中的'UIImage'对象 –

+0

没有帮助.. :(请检查上面的代码 – user3355310

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

这是行不通的 – user3355310

+0

请分享您的完整代码,并且您的视图的屏幕截图 –

+0

编辑..请检查以上 – user3355310

0

尝试这种 把下面的代码在定制单元的方法

- (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]; 
} 

并将其从-cellForItemAtIndexPath中删除。

试试这个

+0

评论这也,我得到了混蛋..所以你可以告诉我关于图像加载的东西? – user3355310

+0

评论你的图片加载代码并尝试。 –

+0

啊哈..然后它工作顺利:) – user3355310