How to hide certain cells in a collection in quick

In my project, I got an array which I upload to my collectionview

var dataSource = ["@", "@", "1", "2", "3", "4", "5", "6", "7", "8" , "9", "10", "@", "@"]

for the string "@" I want to hide this particular cell. so initially I tried to do this with indexpath, and then tried to check if my array got the value "@". But I cannot hide it properly, as some other cells will be changed in the scroll

So this is what I did on my cellForItemAt :

if dataSource[indexPath.row] == "@" {

            cell.contentView.isHidden = true
            cell.layer.borderColor = UIColor.white.cgColor

        }

It is believed that its scrolling is horizontal, and this is my sizeForItemAt :

func collectionView(_ collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAt indexPath: IndexPath) -> CGSize {


        return CGSize(width: (self.numberCollectionView?.bounds.size.width)!/5 - 3, height: (self.numberCollectionView?.bounds.size.width)!/5 - 3 )
    }
+5
source share
2 answers

, , isHidden false 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
}

, , filter.

dataSource = dataSource.filter { $0 != "@" }

collectionView.

+5

dataSource.

    var filtered = dataSource.filter { (item) -> Bool in
       item != "@"
    }

.

+5

Source: https://habr.com/ru/post/1664153/


All Articles