0

I'm experiencing a layout issue with my collectionView. I've set the cell sizes to be different for the first cell (indexPath.row == 0) but then the same afterwards.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
    return CGSizeMake(290.0f, 168.0f);
}
    else {
    return CGSizeMake(144.0f, 114.5f);
    }
}

So that works fine most of the time but when I reload my collectionView:

[viewController.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];

The first cell becomes same size as all the other cells.

I didn't think this would be an issue, any ideas?

  • Are you sure the cell is the wrong size, as opposed to the contents of the cell being the wrong size? This can happen as a result of mangled/missing autoresize masks and/or constraints since the cells are reused. – David Berry Apr 22 '14 at 15:54
  • Hey @David is there anyway to check this? I'm using a custom cell but not using any resizing masks as far as I can see. Not using storyboard or NIB's, just code. – aaronschubert0 Apr 23 '14 at 07:37
  • My favorite to double-check view sizes is change the background colors to something really obnoxious. Are you intending to change the width as well as the height? I can see where that might cause a standard flow layout controller some heartburn, I'd hope not, but... – David Berry Apr 23 '14 at 15:24
  • You've got something going on somewhere other than in this function. If I set up a similar experiment (albeit using storyboards, I'm lazy) the results are more or less as expected. – David Berry Apr 23 '14 at 15:34
  • Hey @David! That was exactly it!! Had it to clear background color and then changed it to black and it is indeed the contents that are being sized wrongly! – aaronschubert0 Apr 24 '14 at 08:36

0 Answers0