我想在UICollectionView上显示一个勾选图标,当取消选择时选择并隐藏它,或者选择第五个单元格! 现在我只能选择一个单元格,如果我选择下一个单元格,第一个单元格上的勾号图标将被隐藏!当我选择第5个单元格时,我想隐藏第一个单元格上的刻度图标,这意味着我一次最多可以选择5个框。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSMutableArray *indexPaths = [NSMutableArray arrayWithObject:indexPath];
if (self.selectedItemIndexPath) {
if ([indexPath compare:self.selectedItemIndexPath] == NSOrderedSame) {
self.selectedItemIndexPath = nil;
} else {
[indexPaths addObject:self.selectedItemIndexPath];
self.selectedItemIndexPath = indexPath;
}
} else {
self.selectedItemIndexPath = indexPath;
}
[collectionView reloadItemsAtIndexPaths:indexPaths];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.selectedItemIndexPath != nil && [indexPath compare:self.selectedItemIndexPath] == NSOrderedSame) {
[cell.tickPhoto setHidden:FALSE];
} else {
[cell.tickPhoto setHidden:TRUE];
}
return cell;
}