2016-11-22 51 views
0

我有流布局的UICollectionView,并根据我的需要它的细胞varing大小,所以我已经实现sizeForItemAtIndexPath委托方法...的CollectionView不同的单元尺寸上reloadItemAtIndex呼叫建立问题

- (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}

并且屏幕停止响应。但是,当给所有的单元格相同的大小这个问题不来,它的工作正常。任何人都可以告诉问题是什么?

回答

0

为了使集合视图大小不同的细胞,你需要实现你的自定义的流程布局按以下链接:

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

我有同样的规定,以显示电池在两个一节时,应用程序是在横向模式和显示如果它在纵向模式下每节一个细胞,我分享了它的演示下面的链接:

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

我希望这将有助于您。

+0

我们可以制作不同大小的单元格,而无需自定义流布局,因为我这样做并且它运行良好....但是发生reloadItemAtIndex方法调用的问题。我没有得到为什么这个运行正常reloadData但不reloadItemAtIndex调用。 – Dipika

+0

嘿这个问题得到解决问题是在我的sizeOfText:(NSString *)constraintWidth:(float)constraintsHeight(float)andFont:(float)方法。反正thxs @harish – Dipika

+0

好吧,这很好,很高兴听到这一点。 –