0

I have got this code let cellId="cellId"

class FeedController: UICollectionViewController,UICollectionViewDelegateFlowLayout{
    let lb: UILabel = {
       let lb = UILabel()
        lb.text="sasa"
        return lb
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(lb);
        navigationItem.title = "Centill"

        collectionView?.backgroundColor = UIColor(white: 0.95, alpha: 1)
        collectionView?.register(FeedCell.self, forCellWithReuseIdentifier: cellId)

    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 9
    }
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)

        return cell
    }
}
class FeedCell: UICollectionViewCell {

    override init(frame: CGRect){
        super.init(frame: frame)

        setupViews()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setupViews(){
        backgroundColor = UIColor.yellow
    }
}

But this code is not working,I have tried adding realoadData,but it didn't work neither,what may be the problem? I am not using storyboard.

0 Answers0