I updated today to Xcode 11 from 10.3, and I started my app on an iPhone simulator running iOS 13. Immediately the app crashed giving the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier EventCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
I have an EventCell.xib
file and an EventCell.swift
file with the EventCell
class in it. Now, I already called collectionView.register()
, and registered my Nib in viewDidLoad()
, in fact this code keeps working on my iOS 12.4 physical device and on iOS 12.2 simulators. I can't figure out what iOS 13 has changed on UICollectionView
, as the code compiles successfully, but it fails on runtime.
Here is where the cell is registered inside viewDidLoad
:
// MARK: UICollectionView
collectionView.register(UINib(nibName: "EventCell", bundle: nil), forCellWithReuseIdentifier: "EventCell")
collectionView.contentInset = UIEdgeInsets(top: 65, left: 0, bottom: 0, right: 0)
collectionView.scrollIndicatorInsets = UIEdgeInsets(top: 65, left: 0, bottom: 0, right: 0)
collectionView.backgroundColor = applicationScheme.colorScheme.backgroundColor
This the code that creates the cell:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "EventCell", for: indexPath) as! EventCell
cell.imageView.image = UIImage(named: "fill")
cell.titleLabel.text = "Titolo di prova"
cell.dateLabel.text = "00/00/0000"
cell.timeLabel.text = "00:00"
return cell
}