I have a collection view with varied item sizes which i declare in
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
FeedItem *item = [_imagesLinkArray objectAtIndex:indexPath.row];
return CGSizeMake(250, 200*item.sizeFactor);
}
When the cell is being reused in collectionView:cellForItemAtIndexPath:
the item is being rendered with the reuesed item size and not the one specified in sizeForItemAtIndexPath:
.
any ideas?
UICollectionView makes adding custom layouts and layout transitions, like those in Photos, simple to build. You're not limited to stacks and grids because collection views are customizable. You can use them to make circle layouts, cover-flow style layouts, Pulse news style layouts and almost anything you can dream up!
An object that manages an ordered collection of data items and presents them using customizable layouts.
Gives the cell a chance to modify the attributes provided by the layout object.
There are no section headers in the UICollectionView. So for your first task, you'll add a new section header using the search text as the section title. To display this section header, you'll use UICollectionReusableView .
It seems that collectionView:layout:sizeForItemAtIndexPath:
is called once on layout preparation, before CollectionView is rendered.
So whenever you scroll and a cell is dequeued it is resized to the size provided by collectionView:layout:sizeForItemAtIndexPath:
at preparation stage. Are you expecting this method to be called whenever a cell with certain indexPath gets visible? So that you can dynamically change cell size? seems this is not how this method can be used, it can be used to determine the size of a cell once at layout preparation stage.
In case you need the sizes to be recomputed for some reason, you can invalidate the layout using [UICollectionViewLayout invalidateLayout]
.
A collection view seems to recompute items less often than a UITableView
. You have to inform the collection view about most of the changes to the underlying model, e.g. by calling [collectionView reloadData]
or [collectionView insertItemsAtIndexPaths:indexPaths]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With