UICollectionViewController多视图错误

时间:2013-06-28 10:21:13

标签: objective-c cocoa-touch uicollectionview

我对UICollectionViewController有疑问。我从默认的视图控制器开始,然后对UICollectionView做一个segue。当我点击链接到该集合的按钮时,我有

错误

 could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

并且信号似乎从那个lign抛出:

 UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

这是什么意思?

1 个答案:

答案 0 :(得分:0)

来自UICollectionView reference:

  

在调用这些方法之一之前,您必须告诉集合   查看如何创建相应的视图(如果尚未创建)   存在。为此,您必须注册类或nib文件   集合视图。例如,在注册单元格时,使用   registerClass:forCellWithReuseIdentifier:或   registerNib:forCellWithReuseIdentifier:方法。作为一部分   注册过程,您指定标识的重用标识符   观点的目的。这与您使用时的字符串相同   后来将观点排成一列。

所以你需要注册一个类或者nib才能得到一个。

注册:

[collectionView registerClass:[MyCellClass class] forCellWithReuseIdentifier:@"MyCellIdentifier"];

出队:

[collectionView dequeueReusableCellWithReuseIdentifier:@"MyCellIdentifier" forIndexPath:indexPath]