[英]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.