There is a method to get a cell by indexPath
(UICollectionView cellForItemAtIndexPath:
). But I can"t find a method to get one of the supplementary views like a header or footer, after it has been created. Any ideas?
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 .
Supplementary views are more related to your data. The collection view layout still decides where to put them, but they are provided by the collection view data source, just like regular cells.
As of iOS 9, you can use -[UICollectionView supplementaryViewForElementKind:atIndexPath:]
to get a supplementary view by index path.
Your best bet is to make your own dictionary mapping index paths to supplementary views. In your collectionView:viewForSupplementaryElementOfKind:atIndexPath:
method, put the view into the dictionary before returning it. In your collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:
, remove the view from the dictionary.
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