简体   繁体   中英

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?

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

如果要从Controller更改补充视图的布局或大小,请使用[self.collectionView.collectionViewLayout invalidateLayout] 。如果只想刷新补充视图,请使用[supplementaryView setNeedsDisplay]如果补充视图为复杂和/或将更改其尺寸。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM