【发布时间】:2019-12-10 18:54:26
【问题描述】:
我正在尝试为 UICollectionView 实现多选。委托函数 didSelectItemAt 被调用,但 didDeselectItemAt 从未被调用,我不知道为什么?我什至不确定它是如何工作的。如果我点击一个单元格 - didSelectItemAt 被调用。因此,如果我再次单击同一个单元格,是否应该调用 didDeselectItemAt?
我的 UIViewController 继承并符合以下所有内容:UICollectionViewDelegate、UICollectionViewDataSource、UICollectionViewDelegateFlowLayout
viewdidLoad():
collectionView.allowsSelection = true
collectionView.allowsMultipleSelection = true
委托功能:
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("didSelectItemAt")
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
print("DESELECT")
}
【问题讨论】:
-
这就是 didSelect 的功能。当您选择另一个单元格时,将调用 didDeselect。您所要求的必须是自定义实现的
-
@GaloTorresSevilla - 感谢您的回复。但在这种情况下,“didDeselectItemAt”永远不会调用我点击的任何内容。
-
@matt - 下面的答案似乎与你所说的相矛盾。我只是不知道为什么没有调用委托函数 'didDeselectItemAt' 尽管allowsMultipleSelection设置为'true'(即使调用了didSelectItemAt)