我正在使用url數組來加載圖像集合視圖。滾動收藏視圖時圖像正在變化。如何解決這個問題?UICollection查看細胞圖像在水平滾動時發生變化
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"RecentProductCell";
RecentProductCell *recentCell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
recentCell.recentProductImg.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSString *imageurl = [[latestProducts valueForKey:@"image"]objectAtIndex:indexPath.item];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]];
dispatch_sync(dispatch_get_main_queue(), ^{
recentCell.recentProductImg.image = [UIImage imageWithData:imageData];
});
});
}
你重用你的細胞,並有取得處理異步發生。獲取數據後,將數據存儲在集合中,並嘗試使用indexpath.row訪問它們,以在每次重用單元時獲取確切的數據。 – erenkabakci
好的,謝謝...... – Lokesh