I'm using a UICollectionView and need a global header and footer together with section headers. Both global header and footer are supposed to scroll with the rest of the content. Basically they should work exactly like UITableView's tableHeaderView and tableFooterView properties.
From what I understand supplementary views are either above or below a specific section and decoration views are functionless. My global header and footer are supposed to have interactive elements.
I'm really pulling my hair out after trying for a couple of hours. I found a couple of nasty ways such as hacking around with contentInsets and adding subview to the collectionview. What I'm really looking for is a clean way to do this.
I'm looking forward to any advice!
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 .
Overview. Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they're scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.
You'll have to create your own custom collection view layout and datasource. The datasource will return global headers and global footers, and section headers and footers, and your custom collection view layout will have to position them accordingly.
THIS IS NOT A VERY SIMPLE PROCESS.
In the WWDC talk Advanced User Interfaces with Collection Views they describe their approach with sample code on how they created a global header. You can use their sample code and then add a global footer section to that.
From Apple:
Advanced User Interfaces with Collection Views
Demonstrates code factoring, swipe to edit, drag reordering, and a sophisticated custom collection view layout.
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