UICardViewController does not load cells

I am making an IOS application using XCode Storyboard. I have a UICollectionViewController in the following structure

UIViewController -> UIView -> UITabBarController -> UICollectionViewController

The app loads without crashing, and UICollectionViewController.viewDidLoad() and .numberOfSections() execute correctly.

But anything that I put in

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)

does not seem to execute. Once the app loads, no cells load. And any print statement in the function doesn't execute either.

All elements have their corresponding class correctly assigned in the Storyboard Identity Inspector, and the cells have the correct reusable identifier.

How can I make it work correctly?

My Collection View Controller:

class ValidCardsCollectionViewController: UICollectionViewController {

    let dataSource: [String] = ["hearts", "clubs", "diamonds", "spades"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        print(dataSource)
    }
    
    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        print("Loading \(dataSource.count) cells")
        return dataSource.count
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        var cell = UICollectionViewCell()
        
        if let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CardCell", for: indexPath) as? CardCollectionViewCell{
            cardCell.configure(with: dataSource[indexPath.row])
            
            cell = cardCell
        }
        
        print("loading cell")
        
        return cell
    }

My UICollectionViewCell:

class CardCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var lblStr: UILabel!
    
    func configure(with str:String){
        lblStr.text = str
    }
}

Storyboard layout:

Simulator:

Welcome to the forum.

Did you check that you have set the delegate and datasource for the collectionView, either in code (in viewDidLoad) or in storyboard ?

Do you mean like this?

class ValidCardsCollectionViewController: UICollectionViewController {

    let dataSource: [String] = ["hearts", "clubs", "diamonds", "spades"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(dataSource)
        
        collectionView.dataSource = self
        collectionView.delegate = self
        
    }

I tried doing this before but it doesn't seem to fix the problem.

I noticed my images weren't visible, so:

My storyboard:

Simulator:

UICardViewController does not load cells
 
 
Q