0

I gotta to create a UICollectionView inside of a UITabBarController. I've trying many ways, but I always end up getting an error.

This is my code at the moment:

import UIKit

class TabBarController: UITabBarController, UICollectionViewDataSource 
{
    @IBOutlet weak var collectionView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.collectionView.dataSource = self

I got an error in self.collectionView.dataSource = self, which is: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value } }

//CollectionView
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 10
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "idCell", for: indexPath)
        cell.backgroundColor = .blue

    return cell
}

This is how I created the screen:

TabBarScreenStoryboard

enter image description here

TabBarController

enter image description here

enter image description here

So, what would be the best way for me to do that?

Gaurav Patel
  • 532
  • 1
  • 5
  • 19

1 Answers1

0

I got to fix by checking the Storyboard where I had a Sigabart error.