9

I'm subclassing UICollectionViewLayout, and the layoutAttributesForItemAtIndexPath: method is never called.

I know to override layoutAttributesForElementsInRect: as well, but I'd rather not have to deal with the rect, as it will be a lot simpler if I just deal with the index path.

If layoutAttributesForItemAtIndexPath: is never called, whats the point of it?

Jonathan.
  • 53,997
  • 54
  • 186
  • 290

3 Answers3

3

layoutAttributesForItemAtIndexPath: is called in different scenarii, when you add new cells to the collection view, when you change the layout, when you reload specific index paths, etc.

You need to implement it, even though it won't get called in the "default" scenario.

Fabien Warniez
  • 2,731
  • 1
  • 21
  • 30
2

layoutAttributesForItemAtIndexPath: is actually called when changing layouts with the animated parameter set to true.

bensj
  • 17
  • 1
0

I was wondering this myself, because I had hoped layoutAttributesForElementsInRect: would call layoutAttributesForItemAtIndexPath:. But it doesn't.

If you want to ensure that the returned layout attributes are always modified, see my answer here: UICollectionViewLayout layoutAttributesForElementsInRect and layoutAttributesForItemAtIndexPath

Community
  • 1
  • 1
Robert
  • 1,936
  • 27
  • 38