制作后,我一直都有点吃力用于储蓄,而该细胞被标记和没有,这个问题并不难不让被选中。经过几次尝试,所有关于保存indePath
的地方,回到视图与收集后,我们能够做array
的array
的indexPaths
内collectionView
方法willDisplay
内的一些东西。基本上,它看起来如何:细胞采集它选择
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
switch collectionView {
case myCollection:
var count: Int = 0
if !SessionMenager.Instance.indexPaths.isEmpty {
for index in SessionMenager.Instance.indexPaths {
if index == indexPath {
print(SessionMenager.Instance.indexPaths.count)
myCollection.selectItem(at: SessionMenager.Instance.indexPaths[count], animated: true, scrollPosition: .bottom)
var image = cell.viewWithTag(1) as! UIImageView
UIView.animate(withDuration: 0.25, animations: {
image.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
image = image.drawRingForCircle(imageView: image, color: .white)
})
cell.isSelected = true
count += 1
}
}
}
default:
break
}
}
这是完美的,但只为一种方式。现在我无法取消选择除去第一个选定的单元格之前的任何其他单元格view
- 为什么?有人能帮助我吗?
提前致谢!
编辑
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath {
switch collectionView {
case xxx:
break
case yyy:
break
case myCollection:
let image = myCollection.cellForItem(at: indexPath)?.viewWithTag(1) as! UIImageView
UIView.animate(withDuration: 0.25, animations: {
image.transform = CGAffineTransform(scaleX: 1, y: 1)
image.layer.sublayers?.removeLast()
})
for (key, _) in tmpDict {
if key == image {
if let index = self.choosenData.index(of: tmpDict[key]!) {
self.choosenData.remove(at: index)
SessionMenager.Instance.indexPaths = SessionMenager.Instance.indexPaths.filter { $0 != indexPath }
}
}
}
default:
break
}
}
嘛,怎么是你想取消细胞?您只发布了选择部分的代码。 –
@PedroCastilho它没有进入方法'didDeselectItemAt'为其他细胞,然后第一个保存。但是,请雇用你! – yerpy
为什么'switch'语句? –