Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView: Is there a way to reload only the supplementary views?

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:

  • when I insert or delete a section it must update the buttons tags, but I don't want to reload all the items from each section.

I've tried:

  • to get the supplementaryViews with the dataSource method collectionView:viewForSupplementaryElementOfKind:atIndexPath: and call layoutIfNeeded method for each supplementaryView, in this way the supplementaryViews are reloading, but this approach multiply my supplementaryViews.
  • a fast for in collectionView.subviews and get just the supplementaryView and call layoutIfNeeded method, but it doesn't reload, just the layout is reloading.
  • reloadSections: method, but this reload all items from the section

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!

like image 535
Irina Avatar asked Nov 18 '14 16:11

Irina


1 Answers

To reload supplementary views you can use -invalidateLayoutWithContext:.

See documentation for UICollectionViewLayoutInvalidationContext and method -invalidateSupplementaryElementsOfKind:atIndexPaths: (available since iOS 8).

like image 154
Marián Černý Avatar answered Sep 27 '22 22:09

Marián Černý