我有一个自定义的item类
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应该给我一个我给它的类型的对象(我想我以前见过这个工作),所以我不知道这里发生了什么。
发布于 2019-06-04 19:15:49
好的,答案很简单:我在nib文件中放错了类:-S
https://stackoverflow.com/questions/56442670
复制相似问题