目前市场上很多应用都包含了筛选功能,自己写了个demo给大家分享一下,共同学习,共同进步
- 先说说常见的collectionView多选功
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
LBFilterModel* filterModel = [self.dataSource objectAtIndex:indexPath.section];
LBFilterListModel* listModel = filterModel.filterList[indexPath.item];
// 改变model选中属性
listModel.isSelected = !listModel.isSelected;
// 刷新indexPath所在行
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects: indexPath, nil]];
// 将选中的model添加到选中的数组中
[self.selectedArray addObject:listModel];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
LBFilterModel* filterModel = [self.dataSource objectAtIndex:indexPath.section];
LBFilterListModel* listModel = filterModel.filterList[indexPath.item];
listModel.isSelected = !listModel.isSelected;
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects: indexPath, nil]];
// 将选中的model从选中的数组中移除
[self.selectedArray removeObject:listModel];
}
- UICollectionView与UITapGestureRecognizer冲突
给背景view添加手势识别
UITapGestureRecognizer*pan = [[UITapGestureRecognizer alloc] initWithTarget:view action:@selector(touchUpbgView)];
pan.