在UicollectionViewCell中使用多个标识符



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

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

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


它确实仅适用于一个标识符,但是当我使用这样的标识符时,它会提供错误消息。

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

由于未被发现的例外,终止应用程序 " nsinternalIncistencyException",原因:'无法脱离观点 种类:带标识符的UicollectionlelementKindcell CollectionViewCell-必须为标识符注册笔尖或类 或连接故事板中的原型单元格'

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

我想同时显示多个自定义单元格。
每个小区都有UISCrollview和UipageControl。
除非我可以设置不同的标识符,否则该实例将被重复使用到新单元格,并且UIPAGECONTROL不会由每个UISCrollView中的运动反应。

您必须为要使用的每个类和单元格调用registerClass:forCellWithReuseIdentifier:

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


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

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

最新更新