how to hide particular cells in collectionview in swift
You are reusing the cell, so you need to add else part also of that condition to set isHidden
to false
and default borderColor
.
if dataSource[indexPath.row] == "@" {
cell.contentView.isHidden = true
cell.layer.borderColor = UIColor.white.cgColor
}
else {
cell.contentView.isHidden = false
cell.layer.borderColor = UIColor.black.cgColor //Set Default color here
}
Also if you doesn't want to show the cell that why don't you remove that element from your array using filter
.
dataSource = dataSource.filter { $0 != "@" }
And now just reload the collectionView
.
You can completely get rid of that cells only by filtering your dataSource array.
var filtered = dataSource.filter { (item) -> Bool in
item != "@"
}
and use this filtered array instead of source.