I'm developing an application for tvOS. It has a tableview and each row of the tableview contains a collectionview. Tableview's focus is disabled so that collectioview cells get focused. When I return a static number as the collectionview items count, the cells are rendered. But when the items count is set dynamically, the cells are not rendered.
The code I used is given below:
class CategoryCVContainerCell: UITableViewCell {
@IBOutlet weak var categoryCollectionView: UICollectionView!
var cellType:CellType?
var sourceViewController: UIViewController?
var media : Media?
override func awakeFromNib() {
super.awakeFromNib()
categoryCollectionView.register(UINib(nibName: "VODType1CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "VODType1CollectionViewCell")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func configureCellUI() {
categoryCollectionView.reloadSections(IndexSet(integer: 0))
}
}
extension CategoryCVContainerCell : UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("////////************------------////////// \(categoryDetails?.media?.count ?? 0)")
let itemsCount = categoryDetails?.media?.count ?? 0 //this code won't render cells
// let itemsCount = 10 // this code works
return itemsCount
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VODType1CollectionViewCell", for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 400.0, height: 250.0)
}
}
Any help is greatly appreciated.