I got this error message when trying to load my project
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier CustomCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
My code is:
extension ViewController: JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let startDate = formatter.date(from: "2017 01 01")!
let endDate = formatter.date(from: "2017 12 31")!
let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate)
return parameters
}
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
cell.dateLabel.text = cellState.text
return cell
}
}
Please help me debug this problem. Thank you.
Edit: I have added the identifier for the cell, but still the error exists.
It is because you haven't registered your xib to UICollectionView. If you are using UICollectionViewCell from Xib, you must register it first.
In viewDidLoad:
write it:
if let xib = NSNib.init(nibNamed: "TemplateNBgCollectionItem", bundle: nil) {
self.collectionView.register(xib, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "cvItem"))
}