0

我想在 UICollectionViewCell 中使用多个标识符。

但似乎我只能为 CollectionView 设置一个重用标识符。

[collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"CollectionViewCell"];


它确实只使用一个标识符,但是当我像这样使用不同的标识符时,它会给出错误消息。

CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"NewID" forIndexPath:indexPath];

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使类型视图出列:带有标识符 CollectionViewCell 的 UICollectionElementKindCell - 必须为标识符注册一个 nib 或一个类或连接情节提要中的原型单元格”

如何在 UICollectionViewCell 中设置多个标识符?

我想同时显示多个自定义单元格。
每个单元格都有 UIScrollView 和 UIPageControl。
除非我可以设置不同的标识符,否则实例将被重用于新单元格,并且 UIPageControl 不会因每个 UIScrollView 中的移动而做出反应。

4

1 回答 1

1

您必须registerClass:forCellWithReuseIdentifier:为您希望使用的每个班级和单元格打电话。

如果要使用具有不同重用标识符的单元格,则必须为它们创建不同的类,然后将这些类注册到该重用标识符的集合视图中。


[collectionView registerClass:[FooCell class] 
    forCellWithReuseIdentifier:@"FooIdentifier"];

[collectionView registerClass:[BarCell class]     
    forCellWithReuseIdentifier:@"BarIdentifier"];

[collectionView registerClass:[ExampleCell class] 
    forCellWithReuseIdentifier:@"ExampleCell"];

现在,您可以使用具有这三个标识符中的任何一个的单元格。

于 2014-01-23T01:59:51.797 回答