adit
adit

Reputation: 33644

how to reload supplementary view in collectionView

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?

Upvotes: 31

Views: 23040

Answers (2)

jhilgert00
jhilgert00

Reputation: 5489

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...
}

Upvotes: 27

Owen Godfrey
Owen Godfrey

Reputation: 3373

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.

Upvotes: 15

Related Questions