how to reload supplementary view in collectionView

前端 未结 2 710
夕颜
夕颜 2020-12-14 16:14

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?

相关标签:
2条回答
  • 2020-12-14 16:25

    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...
    }
    
    0 讨论(0)
  • 2020-12-14 16:28

    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.

    0 讨论(0)
提交回复
热议问题