Reputation: 26
first of all, i did set the delegates. every other protocol is working with collection views. I tested it with the sizeFotItem function. and that worked just fine. But how come that cellForItem function does not respond at all?
Anyone know why?
here is my code;
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.delegate = self
self.collectionView.dataSource = self
let flow = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layoutSettings(flow)
playButtonPressed(self)
}
And this is in my extension of my viewController;
extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 9
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! CollectionCell
print(menu.menuArray[indexPath.row])
cell.cellText.text = menu.menuArray[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Do something")
}
}
The funny part is.. I have almost the same code in an other project, and every is working fine. Only difference is that the project has an collectionView INSIDE a TableView.
Hopefully one of you find an obvious reason why this is not working. I'm gladly to know why :)
thanks.
PS. Is it normal that the editor doesn't recognize the "extension ViewController" part as code?
Upvotes: 0
Views: 466
Reputation: 26
Solved by just deleting the CollectionViewCell and making a new one.
I still don't know what was wrong with my previous collectionViewCell, because every protocol was working just fine except for didSelectItemAt..
If anybody had a familiar problem and knows what was going on, I'm still happy to hear what was going on ;)
Upvotes: 1