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
TabBarController
So, what would be the best way for me to do that?