0

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

        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:). 取消选择会触发其他视图中的事件。这会引发错误,因为我正在取消选择当前不在屏幕上的单元格,因此甚至不在内存中。如何将单元格放入内存中仅一小段时间?我只需要取消选择它们,所以我猜 0.1 秒就足够了。

4

1 回答 1

2

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

func collectionView(_ collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
于 2015-08-28T10:52:15.630 回答