我试图选择UICollectionView
中的单元格,它会被选中,但向下滚动时会选择底部的其他单元格并向上滚动以显示其他要选择的其他单元格。收藏查看更改滚动选定的单元格
下面是我使用didSelectItemAtIndexPath
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *newIndex = indexPath;
cell = (CustomCollectionCell *)[collectionView cellForItemAtIndexPath:newIndex];
NSString *strId = [[masterArray valueForKey:@"id"]objectAtIndex:indexPath.row];
NSString *tempIndexRow = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
NSLog(@"%@, %@,%d ,%@, %d", strId,tempIndexRow,cell.imageView.tag,[boolArray objectAtIndex:indexPath.row],indexPath.row);
if (strId && [[boolArray objectAtIndex:indexPath.row] isEqualToString:@"False"] && cell.imageView.tag == indexPath.row) {
cell.selectedImage.image = [UIImage imageNamed:@"select.png"];
[boolArray replaceObjectAtIndex:indexPath.row withObject:@"True"];
}
else{
cell.selectedImage.image = Nil;
[boolArray replaceObjectAtIndex:indexPath.row withObject:@"False"];
}
}
代码这是我选择的第一次
这是我所得到的,当我向下滚动
感谢
一样一样的tableview需要保存在某个地方哪个小区被选择,在这种方法“ - (UICollectionViewCell *)的CollectionView:(UICollectionView *)的CollectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath“管理你的图片 – Leena