Is there an easy way to reload the suppplementary view only in a UICollectionViewFlowLayout? I don't want to reload the whole thing. Is it possible to do so?
After reviewing the documentation, I'm not sure about reloading an individual supplementary view, but you can use reloadSections:
to update 1 or more sections in the UICollectionView. (documentation) So when a section header needs updating, you can call:
Objective-C:
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];
Swift:
self.collectionView?.reloadSections(IndexSet(0 ..< 3))
Which happens to call:
- (UICollectionReusableView *)collectionView: (UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { //Place logic for handling update here... }
If you want to change the layout or size of the supplementary view from the Controller, use[self.collectionView.collectionViewLayout invalidateLayout]
.If you want to refresh the supplementary view only,use [supplementaryView setNeedsDisplay]
.Use both if the supplementary view is complex and/or will change its dimensions.
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