大型UICollectionViewCell随着自定义布局而消失

时间:2012-12-07 20:27:49

标签: iphone ios uicollectionview

我已经UICollectionViewLayout了。到目前为止,这么好 但是,我有一些比屏幕更宽的单元格,有时这些单元格在滚动时会消失。当你滚动更多时,它们会神奇地重新出现在应有的位置。我可以向你展示我的代码,但我认为它没有任何问题,因为它在90%的情况下有效。但是,真正大的单元格(超过屏幕大小的两倍)有时会消失。

NSMutableArray* attributes = [NSMutableArray array];
for (int section=0; section < [[self collectionView] numberOfSections]; section++) {
    [attributes addObject:[self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]]];
        for (int row=0; row < [[self collectionView] numberOfItemsInSection:section]; row++) {
            NSIndexPath* indexPath = [NSIndexPath indexPathForItem:row inSection:section];
            [attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
        }
 }
 return attributes;

我还有这些帖子:UICollectionView's cell disappearingLarge cells in a UICollectionView getting removed while the cell is still displayed 但是,没有提到解决方案。任何人都可以帮我吗?这可能是Apple的问题吗?如果是的话,我自己能做些什么来解决它?

2 个答案:

答案 0 :(得分:5)

很抱歉告诉你:我很确定这是UICollectionView中的一个真正的错误;几周前我遇到了同样的事情。我已经制作了一个小程序来演示这个bug,并向Apple提交了一个RADAR,但是还没有听说他们是否计划修复它。我能想到的最好的解决方法(警告:我还没有实现这个解决方法)是要注意布局属性离屏幕边缘很远,故意改变单元格属性的边界,所以它只是略微偏离屏幕,并可能存储该偏移量(您修剪的实际边界应该是多少)作为layoutAttributes中的附加自定义字段,因此您的单元格知道正确绘制它的内容。这感觉就像一个严重的黑客,但它应该工作。

答案 1 :(得分:0)

当调用方法-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect并且rect只是单元格的一部分时,您确定为此单元格返回正确的属性对象吗?