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

时间:2013-01-12 02:42:58

标签: iphone ios objective-c ipad

是否有一种简单的方法只能在UICollectionViewFlowLayout中重新加载补充视图?我不想重装整件事。是否可以这样做?

2 个答案:

答案 0 :(得分:24)

在查看文档后,我不确定是否重新加载单个补充视图,但您可以使用reloadSections:更新UICollectionView中的1个或多个部分。 (documentation)因此,当部分标题需要更新时,您可以调用:

目标-C:

[self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];

夫特:

self.collectionView?.reloadSections(IndexSet(0 ..< 3))

这恰好叫:

- (UICollectionReusableView *)collectionView: (UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

       //Place logic for handling update here...
}

答案 1 :(得分:10)

如果要从Controller更改补充视图的布局或大小,请使用[self.collectionView.collectionViewLayout invalidateLayout]。如果只想刷新补充视图,请使用[supplementaryView setNeedsDisplay]。如果要补充视图,请同时使用两者是复杂的和/或会改变它的尺寸。