0

How can I tell my UICollectionViewFlowLayout custom subclass to use a static, fixed item width value?

I would like my delegate to implement a custom method:

collectionView:layout:heightForItemAtIndexPath:

to return a variable item height, while the width is fixed. The width is calculated upon the collection view bounds and the section inset:

width = collectionView.bounds.width - sectionInset.left - sectionInset.right

I have created a custom UICollectionViewLayout subclass, but it gives me, unsurprisingly, a poor performance, so I'm looking forward to subclass the flow layout instead.

And don't tell me about UITableView. I know it exists.

akashivskyy
  • 44,342
  • 16
  • 106
  • 116
  • Just a guess: Since a flow layout consists of individual cells, you'd have those cells have their size control what you want. In particular, you'd use the delegate's "collectionView:layout:sizeForItemAtIndexPath:" for that. – Thomas Tempelmann Apr 20 '14 at 19:16
  • Implementing `sizeForItemAtIndexPath:` is exactly what I **don't** want to do. – akashivskyy Apr 20 '14 at 19:53
  • What gives you the idea that there's another solution then? `sizeForItemAtIndexPath` is the most direct - after all, a cell's size is what the layout needs to know in order to be able to determine the widths of the cells. Even the docs explain this. – Thomas Tempelmann Apr 20 '14 at 19:55
  • I want to create a table-like layout. Width doesn't matter, and the delegate shouldn't worry about it. Only the height is important. That's why I want to create a custom layout. What else don't you understand? – akashivskyy Apr 20 '14 at 19:58

1 Answers1

0

Okay, I ended up by subclassing UICollectionViewLayout, thus fixing ald the bad performance issues.

However, if someone eventually comes up with an answer to my question, I will gladly accept it.

akashivskyy
  • 44,342
  • 16
  • 106
  • 116