0

See the image attached.UICollectionViewCell missing

I'm using a fairly basic UIFlowLayout subclass to accompany the view, but no matter what I've tried, it decides that it doesn't need to draw cell 0,

However if I scroll down and back up, it will then draw it properly.

It seems like it's a iOS SDK bug, but need to investigate further. Just wondering if anyone knows any ideas to try with this.

Daniyar
  • 2,975
  • 2
  • 26
  • 39
David van Dugteren
  • 3,879
  • 9
  • 33
  • 48

1 Answers1

0

This answer actually help solve it:

UICollectionView flowLayout not wrapping cells correctly (iOS)1

But my case was unique as I was using a UIDynamicAnimator to calculate the layout attributes.

So my code went from this:

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    return [self.dynamicAnimator itemsInRect:rect];
}

-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    return [self.dynamicAnimator layoutAttributesForSupplementaryViewOfKind: kind atIndexPath:indexPath];
}

TO this:

-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
    NSMutableArray *newAttributes = [NSMutableArray arrayWithCapacity:attributes.count];
    for (UICollectionViewLayoutAttributes *attribute in attributes) {
        if ((attribute.frame.origin.x + attribute.frame.size.width <= self.collectionViewContentSize.width) &&
            (attribute.frame.origin.y + attribute.frame.size.height <= self.collectionViewContentSize.height)) {
            [newAttributes addObject:attribute];
        }
    }
    return newAttributes;
}

-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    return [self.dynamicAnimator layoutAttributesForSupplementaryViewOfKind: kind atIndexPath:indexPath];
}

AND PROBLEM SOLVED! It's plausable that the logic in my code for -(BOOL)shouldInvalidateLayoutForBoundsChange was doing something wrong, but I had already checked that and the logic looked fine.

Community
  • 1
  • 1
David van Dugteren
  • 3,879
  • 9
  • 33
  • 48