-1

I am using a uicollectionview to populate a grid (4x5 cells).Now, sometimes, but not always, I am getting 2 cells that are not aligned with the grid, but they are ~1/4 of the cell size off to the left or right. It appears consistently but not every time the grid is populated.

Has anyone seen this happening before? Any tips on how to identify the cause would be helpful.

cell moved outside the grid

Vinodh
  • 5,262
  • 4
  • 38
  • 68
Koen
  • 49
  • 1
  • 6
  • Best solution is http://stackoverflow.com/questions/42956954/ios-horizontally-scrolling-collectionview-with-images/42957646#42957646 – user3182143 Mar 23 '17 at 02:46

2 Answers2

0

try to implement

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat cellSize =  [UIScreen mainScreen].bounds.size.width/4;

    return CGSizeMake(cellSize, cellSize);
}

and setting your collection view layout:

 -(void)setCollectionViewLayout {

    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.minimumInteritemSpacing = 2;
    flow.minimumLineSpacing = 2;

    [yourCollectionView setCollectionViewLayout:flow];
}
Vinodh
  • 5,262
  • 4
  • 38
  • 68
Ayman Karram
  • 116
  • 4
0

I managed to locate a similar error post that resolved the situation for me.

[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];
then:

[self.collectionView reloadData];

https://stackoverflow.com/a/19100840/7753681

Community
  • 1
  • 1
Koen
  • 49
  • 1
  • 6