arrays - 从 makeItem 崩溃中向下转换 NSCollectionViewItem
问题描述
我有一个自定义项目类
class AttachmentCell: NSCollectionViewItem {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
我尝试在委托中实例化为
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView
.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "AttachmentCell"),
for: indexPath) as! AttachmentCell
return item
}
现在程序因错误而崩溃
Could not cast value of type 'NSCollectionViewItem' (0x7fffa5050690) to 'Notes.AttachmentCell' (0x10000ee38).
2019-06-04 13:01:33.603441+0200 Notes[18477:37049533] Could not cast value of type 'NSCollectionViewItem' (0x7fffa5050690) to 'Notes.AttachmentCell' (0x10000ee38).
我的理解是 makeItem 应该给我一个我给它的类型的对象(我想我以前看过这个工作),所以我不知道这里发生了什么。
解决方案
好的,答案很简单,我在 nib 文件中放错了类:-S
推荐阅读
- database - 在表单上显示查询结果的问题
- google-sheets - LOOKUP Function won't output correct value
- python - 如何在 excel 单元格中自动执行此 python 代码?
- reactjs - SharedKeyCredential 不是构造函数。Azure 存储反应应用
- nginx - 如何在 Nginx 中对字符串进行哈希处理?
- python - 函数 set_weights() 的问题
- cryptography - 数字签名每次都不一样
- python - Fbprophet 安装错误 - 无法构建轮子
- javascript - 如何处理来自函数数组的重复函数调用?
- python - 我该如何解决:'int' 对象不可迭代