0

我想在UICollectionViewCell中使用多個標識符。

但似乎我只能爲CollectionView設置一個重用標識符。在UICollectionViewCell中使用多個標識符

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


這真的只用一個標識工作,但是當我使用不同的標識符這樣的,它提供了錯誤信息。

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

終止應用程序由於未捕獲的異常 「NSInternalInconsistencyException」,原因:「無法出列的視圖種 :UICollectionElementKindCell具有標識符 CollectionViewCell - 必須註冊標識符的筆尖或一類 或連接故事板中的原型單元格'

如何在UICollectionViewCell中設置多個標識符?

我想同時顯示多個自定義單元格。
每個單元格都有UIScrollView和UIPageControl。
除非我可以設置不同的標識符,否則該實例將被重新用於新單元,並且UIPageControl不會被每個UIScrollView中的移動所反應。

+1

您是否嘗試註冊其他類/標識符? – nhgrif

回答

1

您必須爲每個想要使用的課程和單元調用registerClass:forCellWithReuseIdentifier:

如果要使用具有不同重用標識符的單元格,則必須爲它們創建不同的類別,然後將這些類別與該重用標識符的集合視圖一起註冊。現在


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

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

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

,你可以使用一個細胞與任何這三個標識符。

相關問題