我在尝试加载我的项目时收到此错误消息
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使类型的 View 出列:具有标识符 CustomCell 的 UICollectionElementKindCell - 必须为标识符注册一个 nib 或一个类,或者连接 Storyboard中的原型(prototype)单元格”
我的代码是:
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
}
}
请帮我调试这个问题。谢谢。
编辑:我已经为单元格添加了标识符,但错误仍然存在。
最佳答案
在viewDidLoad
方法中:
您必须使用 collectionView 对象注册您的自定义单元类/xib 名称。
如果你只有类自定义类那么你通过以下方式注册(没有xib文件)
collectionView.register(CustomCell.self, forCellWithReuseIdentifier: "cellId")
如果你既有class又有xib文件那么你可以通过这种方式注册
collectionView.register(UINib(nibName: "CustomCell", bundle: nil), forCellWithReuseIdentifier: "cellId")
关于ios - Swift - 无法使 : UICollectionElementKindCell 类型的 View 出队,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43734614/