gpt4 book ai didi

ios - 停止 Collection View 取消选择一个项目

转载 作者:可可西里 更新时间:2023-11-01 00:36:02 25 4
gpt4 key购买 nike

我有一个 UICollectionView,它是一个日历。这是一个可滚动的行。某些日期无法选择,因为该日期没有数据。其他可选择,因为该日期有数据。

选择日期后,日历会在所选日期下划线并将它滚动到 UICollectionView 的中心。

当点击一个没有日期的日期时,我有这个功能......

override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return //is there data for the date at this indexPath?
}

这会停止选择这些单元格...但是,它仍然会取消选择之前选择的单元格。

有一个 shouldDeselect 函数,但我不能使用它,因为我不知道被点击的单元格的索引。所以我无法确定是否应该取消选择该项目。

有更好的方法吗?

最佳答案

当我重新加载 Collection View 时,它对我来说很简单:

func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
// return true whithout reloadData when necessarily
collectionView.reloadData()
return false
}

关于ios - 停止 Collection View 取消选择一个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41043688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com