我实现了启用了多个选择的UICollectionView。

我的某些单元格是可选的,有些不是。这是事件链:

  • 我通过点击一些单元格并将YES返回到
  • shouldHighlightItemAtIndexPath:
  • shouldSelectItemAtIndexPath:
  • 我尝试通过点击它来选择一个不可选择的单元格(不可选择的方面是通过将NO返回到shouldSelectItemAtIndexPath:来实现的)
  • 结果:取消选择所有选定的单元格,并在它们上调用didDeselectItemAtIndexPath:。注意:不会调用shouldDeselectItemAtIndexPath:

  • 预期结果:无任何 react 。

    这是正常行为吗?我在文档中找不到任何内容。如果是这样,我该如何不取消选择单元格呢?

    最佳答案

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeue...
    
        cell.userInteractionEnabled = isSelectableIndexPath(indexPath)
    
        return cell
    }
    
    func isSelectableIndexPath(indexPath: NSIndexPath) -> Bool {
        //logic to check if cell is selectable
    }
    

    这通过禁用与​​单元的交互来起作用。

    10-05 20:20
    查看更多