製作後,我一直都有點吃力用於儲蓄,而該細胞被標記和沒有,這個問題並不難不讓被選中。經過幾次嘗試,所有關於保存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'語句? –