简体   繁体   English

如何在collectionView中重新加载补充视图

[英]how to reload supplementary view in collectionView

Is there an easy way to reload the suppplementary view only in a UICollectionViewFlowLayout? 是否有一种简单的方法可以仅在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. 阅读文档后,我不确定是否要重新加载单个补充视图,但是可以使用reloadSections:更新reloadSections: 1个或多个部分。 ( documentation ) So when a section header needs updating, you can call: 文档 )因此,当节标题需要更新时,可以调用:

Objective-C: 目标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]如果补充视图为复杂和/或将更改其尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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