【发布时间】:2012-12-24 10:41:20
【问题描述】:
我正在尝试设置UICollectionView。起初我使用的是基本的UICollectionViewCell,它运行良好,正在显示单元格。
然后我创建了自己的 collectionViewCell(子类化UICollectionViewCell),以便能够在单元格中显示图像。
我将 Storyboard 中的自定义单元格与一个标识符相关联,并且我还为它指定了正确的类。
但是,我一直有这个错误,我不明白为什么:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier MediaCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
我设法通过在viewDidLoad 中添加这一行来解决这个错误,但在我关注的教程中,这些人没有使用它:
[self.collectionView registerClass:[MediaCollectionViewCell class] forCellWithReuseIdentifier:@"MediaCell"];
问题是,如果我添加它,collectionView仍然是黑色的,没有数据显示。
【问题讨论】:
标签: iphone ios cocoa-touch uicollectionview uicollectionviewcell