Declare one instance of type IndexPath
and maintain the cell status is it selected
or not with it. Now use this array within cellForItemAt indexPath
and didSelectItemAt indexPath
like this.
var selectedIndexPaths = IndexPath()
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PlaceCollectionViewCell
//Your code
//decide weather to show tick image or not
self.tickImageView.isHidden = self.selectedIndexPaths != indexPath
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if self.selectedIndexPaths == indexPath {
self.selectedIndexPaths = IndexPath()
}
else {
self.selectedIndexPaths = indexPath
}
self.tableview.reloadData()
}
8
solved How to show an image in a UICollection View cell while clicking that cell in swift ios?