If i try to return the default UICollectionViewCell
the app crashes because it is missing a reuseIdentifier:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier - cells must be retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath:'
The code:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return UICollectionViewCell()
}
With UITableViewCells
it's working just fine. What is the best practice for default returns in UICollectionViews
?
What works for me is:
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "default")
and then:
return collectionView.dequeueReusableCell(withReuseIdentifier: "default", for: indexPath)
as the default return. But i was hoping for something cleaner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With