I'm implementing a custom flow layout. It has 2 main methods for overriding to determine placement of cells: layoutAttributesForElementsInRect
and layoutAttributesForItemAtIndexPath
.
In my code, layoutAttributesForElementsInRect
is called, but layoutAttributesForItemAtIndexPath
isn't. What determines which gets called? Where does layoutAttributesForItemAtIndexPath
get called?
layoutAttributesForElementsInRect:
doesn't necessarily calllayoutAttributesForItemAtIndexPath:
.In fact, if you subclass
UICollectionViewFlowLayout
, the flow layout will prepare the layout and cache the resulting attributes. So, whenlayoutAttributesForElementsInRect:
is called, it won't asklayoutAttributesForItemAtIndexPath:
, but just uses the cached values.If you want to ensure that the layout attributes are always modified according to your layout, implement a modifier for both
layoutAttributesForElementsInRect:
andlayoutAttributesForItemAtIndexPath:
: