Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewLayout when is layoutAttributesForItemAtIndexPath called

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?

like image 911
Jonathan. Avatar asked Sep 24 '13 18:09

Jonathan.


2 Answers

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.

like image 139
Fabien Warniez Avatar answered Sep 26 '22 02:09

Fabien Warniez


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

like image 43
bensj Avatar answered Sep 22 '22 02:09

bensj