簡體   English   中英

不同單元格大小的Collectionview在reloadItemAtIndex調用上產生問題

[英]Collectionview with different cell sizes creating issues on reloadItemAtIndex call

我有一個帶有流布局的UICollectionView,根據我的需要,它的單元格大小各不相同,因此我已將sizeForItemAtIndexPath委托方法實現為...

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGSize estimatedSize;
estimatedSize.width = collectionView.frame.size.width - 2* MARGIN_8;
CGSize questionSize=[self sizeOfText:myData[indexPath.row] constraintWidth:estimatedSize.width constraintsHeight:MAXFLOAT andFont:CELL_FONT];
estimatedSize.height = ceil(questionSize.height>MINIMUM_HEIGHT_OF_OPTION_TEXT?questionSize.height:MINIMUM_HEIGHT_OF_OPTION_TEXT);return estimatedSize;}

現在,問題是當調用reloaItemAtItem方法以更新選定的單元格為...時。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
userSelection = (int)indexPath.row;
[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];}

它說

UICollectionView recieved layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0x147a0190> {length = 2, path = 1 - 0}

然后屏幕停止響應。 但是,當為所有單元格提供相同大小時,此問題不會出現,並且可以正常工作。 誰能說出問題是什么?

要使用不同大小的單元格制作集合視圖,您需要按照以下鏈接實現自定義流程布局:

https://bradbambara.wordpress.com/2014/05/24/getting-started-with-custom-uicollectionview-layouts/

我有相同的要求,即當應用程序處於橫向模式時,在一個部分中顯示兩個單元格,如果應用程序處於縱向模式,則在每個部分中顯示一個單元格,我在下面的鏈接上共享了該演示的示例:

https://drive.google.com/file/d/0BzVs5BNlAI6qdjcwcnVHN1Z5NW8/view

我希望這能幫到您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM