Sina Kaheh
Sina Kaheh

Reputation: 1

UICollectionViewCell: how to have each cell with different naming

I want to have my cells with different titles but it keeps displaying same for all I tried to use two dimensional array but didn't really know how to implement it

any help will be highly appreciated,

class DequedCEll: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
    setupViews()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

// this is the part where i stuck 

    let Mainlabel : UILabel = {
        var label = UILabel()
        label.text = "??"
        label.font = UIFont.boldSystemFont(ofSize: 45)

       return label
    }()

    func setupViews () {

        backgroundColor = .yellow
        addSubview(Mainlabel)

        Mainlabel.anchorToTop(self.topAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor)

    }


}

Upvotes: 0

Views: 18

Answers (1)

HalR
HalR

Reputation: 11073

I assume that somewhere in your code you are dequeueing the collectionViewCell. You can set the label right after you dequeue your cell.

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: yourCellIdentifier, for: indexPath) as? DequedCEll else { return DequedCEll() }

    cell.Mainlabel.text = "your text here from you array, probably using indexPath to determine what text to use"
    return cell
}

Upvotes: 1

Related Questions