我将 UICollectionView 用于图像网格外观。滚动时我发现那里出现了重复的图像。我正在使用 NYXProgressiveImageView 下载和显示图像。我已经实现了在搜索中找到的几种方法..
这是我的代码
- (MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
if (cell == nil)
{
cell = [[MyCell alloc]init];
[cell.imgv setImage:nil];
}
NSMutableDictionary *d=[[NSMutableDictionary alloc]initWithDictionary:[arrSubCatAndItems objectAtIndex:indexPath.item]];
[cell.imgv setImage:nil];
cell.imgv.cakeIndex=indexPath.item;
cell.cellLabel.text = [d objectForKey:@"Name"];
return cell;
}
Mycell 是具有 ImageView 和标签 init 的自定义 UICollectionViewCell 类在滚动时加载这样的可见图像
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
_isDragging=NO;
if (!decelerate)
{
_isDragging=YES;
[self loadimages];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGPoint contentOffset = testscroll.contentOffset;
CGRect contentFrame = testscroll.bounds;
contentFrame.origin = contentOffset;
if(!_isDragging)
[self loadimages];
}
-(void)loadimages
{
for (UICollectionViewCell *cell in [collectionview visibleCells]) {
NSIndexPath *indexPath = [collectionview indexPathForCell:cell];
MyCell *cell1 = (MyCell*)[collectionview cellForItemAtIndexPath:indexPath];
NSMutableDictionary *d=[[NSMutableDictionary alloc]initWithDictionary:[arrSubCatAndItems objectAtIndex:indexPath.item]];
[cell1.imgv loadImageAtURL:[NSURL URLWithString:[[d objectForKey:@"ImageUrl"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
}
如果我在 Imageview 中加载图像时滚动集合视图,则主要问题出现在下面的单元格中
我不知道我哪里出错了...... UICollectionView 的新手......请提前帮助我..Tnx