I was using UICollectionView for Images grid appearance.while scrolling i found duplicate images appearing there. I was using NYXProgressiveImageView for downloading and displaying images. I Have implemented several methods found on search..
This is my code
- (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;
}
Where as Mycell is Custom UICollectionViewCell class having ImageView and label init On scrolling iam loading visible images like this
- (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]]];
}
}
Main problem if i scroll collection view on loading image in Imageview it is appearing in below cells
I don't Know where I am going wrong....New to UICollectionView...Please help me ..Tnx in advance