我正在制作一个 Collection View ,并制作了我自己的自定义 collectionCell。我已经在身份检查器中指定了,据我所知,我做的一切都是正确的。
代码是
import UIKit
class SubjectCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var label: UILabel!
}
在我的 collectionViewController 中
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! SubjectCollectionViewCell
return cell
}
我收到以下错误消息
“无法将‘UICollectionViewCell’ (0x110460820) 类型的值转换为‘project.SubjectCollectionViewCell’ (0x10eceeda0)。 (lldb)”
最佳答案
引用:Could not cast value of type 'UICollectionViewCell'
如果您在 collectionViewController 中看到它,请将其删除。
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
关于swift - 为什么我不能将 UICollectionViewCell 向下转换为它的子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36942694/