0

I am having a problem where it seems that my UICollectionView thinks that my screen is smaller (iPad Air) , and he fail to load the next cells in time ,and load them in late-cause "holes". I have 2 columns,dynamic cell height,and subclassed the layout to get constant vertical spacing.

I could see now, that the only thing that solves this problem for me = let the UICollectionView load more cells so i can scroll down and NOT see a blank spaces, is to set the height of the collectionView to be much higher than screen size . Now, all cells are loaded just in time when scrolling down. BUT , now when i scroll back up , i get the same effect of empty spaces . Empty means that half screen is empty ,and only when i continue scrolling ,he loads these cells in late.

I just can't seem to solve this issue for a while, but i think i might do something wrong with setting the relationship between the layout and the colleciontview content sizes .

Here is how i set them :

 //collection view
    TopAlignedCollectionViewFlowLayout *layout=[[TopAlignedCollectionViewFlowLayout alloc] init];

    CGRect  size=CGRectMake( ([UIScreen mainScreen].bounds.size.width-collectionWidth)/2,
                            upperLineMargin, collectionWidth, (6.*[UIScreen mainScreen].bounds.size.height )); //seting *6 soves the problem.


    self.GridView=[[UICollectionView alloc] initWithFrame:size collectionViewLayout:layout];
    [self.GridView registerClass:[GridCell class] forCellWithReuseIdentifier:@"Cell"];
     //[ layout setItemSize:CGSizeMake(collectionWidth, [UIScreen mainScreen].bounds.size.height )];

This issue only happens after i was trying to subclass the layout for the equal spacing between rows. We are now in the situation that we don't have where to go, and we can't use the collection with this bug, because that temporary blank spaces not looks good .

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
      if (indexPath.item < numColumns)
    {
        CGRect f = currentItemAttributes.frame;
        f.origin.y = 0;
        currentItemAttributes.frame = f;
        return currentItemAttributes;
    }


    NSIndexPath* ipPrev = [NSIndexPath indexPathForItem:indexPath.item-numColumns inSection:indexPath.section];
    CGRect fPrev = [self layoutAttributesForItemAtIndexPath:ipPrev].frame;
    CGFloat YPointNew = fPrev.origin.y + fPrev.size.height + 10;
    CGRect f = currentItemAttributes.frame;
    f.origin.y = YPointNew;
    currentItemAttributes.frame = f;
    return currentItemAttributes;
}
Curnelious
  • 1
  • 16
  • 76
  • 150
  • 2
    You do not need to increase the size of your collection view. Sounds like a cell reuse issue to me. Please post your `cellForItemAtIndexPath` implementation. – Timothy Moose May 16 '14 at 14:30
  • I agree with @TimothyMoose - the delay sounds like your implementation of `cellForItemAtIndexPath` is too slow, perhaps operating on a background thread or trying to perform networking or similar. – matt May 16 '14 at 14:37
  • @matt I don't think thats the issue for 2 reasons: 1. why is this happens only when i subclass the layout ? it acts great without the subclass? 2. i have tried to remove everything from the cellForItem method, and it still occurs... (i do have there async loading.. ) – Curnelious May 16 '14 at 15:06
  • I have just tried again to remove everything from the cellForIndexPath, and it still occurs! i can see the cells empty and still there are holes in it . Try your self to implement the subclassing with a dynamic height and you will get the same effect ! – Curnelious May 16 '14 at 15:09
  • I had decided to start a new question and show a simple new project that reproduce this bug , you can have a look here :http://stackoverflow.com/questions/23699016/a-uicollectionview-bug-with-a-dynamic-height – Curnelious May 16 '14 at 15:23

0 Answers0