gpt4 book ai didi

ios - 取消选择当前不可见的单元格

转载 作者:行者123 更新时间:2023-11-29 01:42:13 25 4
gpt4 key购买 nike

我正在尝试取消选择以前选择但当前在 Collection View 中不可见的单元格。我正在使用这段代码:

        let optionalSelectedItems = collectionView.indexPathsForSelectedItems()
if let selectedItems = optionalSelectedItems{
for indexPath in selectedItems{

self.collectionView.deselectItemAtIndexPath(indexPath, animated: true)
self.collectionView.delegate?.collectionView!(self.collectionView, didDeselectItemAtIndexPath: indexPath)
}

在我的 func collectionView(_:didDeselectItemAtIndexPath:) 实现中,有一些非常重要的事情正在发生。取消选择会触发其他 View 中的事件。这会引发错误,因为我正在取消选择当前不在屏幕上的单元格,因此甚至不在内存中。如何将单元格放入内存中一小段时间?我只需要取消选择它们,所以我猜 0.1 秒就足够了。

最佳答案

您可以将选定行的索引存储在单独的数组中,并在创建后选择/取消选择单元格

func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell

关于ios - 取消选择当前不可见的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32269253/

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