Reputation: 191
I have an uicollectionview with supplementaryView for each section. In each supplementaryView I have some buttons. In dataSource method collectionView:viewForSupplementaryElementOfKind:atIndexPath: I'm setting the buttons tags with the indexPath.section. I made some delegate methods when a button is pressed and send the section(button.tag) as parameter.
Everything works fine, but here comes the problem:
I've tried:
Ohh.. And I use NSFetchedResultsController(delegate) for inserting and deleting sections.
Can anyone help me with this? Is there a way to reload only the supplementaryView? Is there other approach for this scenario?
Thank You!
Upvotes: 19
Views: 15925
Reputation: 10378
Instead of reloading these views, getting a reference to each visible supplementary view so that you can change the tag might be sufficient for your needs.
There is a simple method you can use to do this:
let supplementaryViews = collectionView.visibleSupplementaryViews(ofKind: "identifier")
https://developer.apple.com/documentation/uikit/uicollectionview/1618026-visiblesupplementaryviews
Upvotes: 11
Reputation: 15738
To reload supplementary views you can use -invalidateLayoutWithContext:
.
See documentation for UICollectionViewLayoutInvalidationContext
and method -invalidateSupplementaryElementsOfKind:atIndexPaths:
(available since iOS 8).
Upvotes: 12