Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
adit Avatar asked Jan 12 '13 02:01

adit


2 Answers

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... } 
like image 75
jhilgert00 Avatar answered Oct 02 '22 11:10

jhilgert00


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.

like image 41
Owen Godfrey Avatar answered Oct 02 '22 12:10

Owen Godfrey