我正在尝试设置一个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'
Run Code Online (Sandbox Code Playgroud)
我设法通过添加这一行来处理这个bug,viewDidLoad但在我关注的教程中,这些人没有使用它:
[self.collectionView registerClass:[MediaCollectionViewCell class] forCellWithReuseIdentifier:@"MediaCell"];
Run Code Online (Sandbox Code Playgroud)
问题是如果我添加它,collectionView将保持黑色并且不显示任何数据.
iphone cocoa-touch ios uicollectionview uicollectionviewcell