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