When
collectionView.allowsMultipleSelection = YES;
我可以取消选择已选择的单元格。
when
collectionView.allowsMultipleSelection = NO;
我无法取消选择已选择的单元格。
反正我只能设置
collectionView.allowsMultipleSelection = NO;
and
能够取消选择选定的单元格吗?所以要么被选中,要么没有被选中。
我知道您可以使用点击手势来实现您自己的选择,然后在检测到手势时调用 setSelected。但我正在寻找一种更原生的解决方案,您可以在 uicollectionView 本身上进行配置。
Thanks!
我遇到了同样的问题,但找不到本地解决方案。这就是我最终的做法,有点老套,但它满足了需要。我有self.collectionView.allowsMultipleSelection = YES
set in viewDidLoad
.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
for (NSIndexPath *selectedIndexPath in [self.collectionView indexPathsForSelectedItems]) {
[self.collectionView deselectItemAtIndexPath:selectedIndexPath animated:NO];
}
[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
}
中的附加选择和取消选择didDeselectItemAtIndexPath
是动画取消选择 - 这种方法提供的另一个好处是能够动画转换。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)