私はiOSが初めてで、UITableviewのセクション1で複数の選択/選択解除を行うことができるUITableView内にUICollectionViewを実装したいと考えています。セクション 2 では、単一の選択のみが許可されます。Viewcontrollerを閉じると選択状態イベントを保存し、再度開くと、最後に選択したセルをハイライトとして表示する必要があります。
チュートリアルを検索しましたが、コレクションセルの状態を選択/選択解除したり、ビューコントローラーを閉じた後に状態を保存したりすることについては言及されていません。
誰かがそれを実装するのを助けることができますか?
少し早いですがお礼を!
ここに私が今までやっている私のコードがあります:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return clvData.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "clvCell", for: indexPath) as! demoCollectionViewCell
cell.title.text = clvData[indexPath.item] as? String
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.backgroundColor = .red
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.backgroundColor = .white
}
ここで私のプロジェクトを確認することもできます: https://mega.nz/#!xRs0EQyQ