gpt4 book ai didi

objective-c - 如何重新加载 UICollectionView 补充 View (HeaderView)

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:24 26 4
gpt4 key购买 nike

要事第一:

  1. I do NOT Want to reload whole CollectionView.
  2. I also do NOT want to reload the section either (since it is same as reloadData because my cv only has 1 section).

我在补充 View 中放置了一些控件,因为该 View 充当标题 View 。在某些情况下,我想根据需要隐藏/显示控件。为此,我需要重新加载补充 View ,因为它的数据已经更新。

我尝试过的:

UICollectionViewLayoutInvalidationContext *layoutContext =
[[UICollectionViewLayoutInvalidationContext alloc] init];
[layoutContext invalidateSupplementaryElementsOfKind:UICollectionElementKindSectionHeader
atIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]]];
[[_collectionView collectionViewLayout] invalidateLayoutWithContext:layoutContext];

当然是这次崩溃。代码看起来也不正确,但我不确定如何正确构造 UICollectionViewLayoutInvalidationContext 并告诉 collectionview 仅重新加载补充 View 。

谢谢。

最佳答案

如果您只需要更新特定部分的标题 View ,那么您可以执行类似的操作:

if let header = collectionView.supplementaryView(forElementKind: UICollectionElementKindSectionHeader, at: IndexPath(item: 0, section: indexPath.section)) as? MyCollectionHeaderView {
// Do your stuff here
header.myLabel.isHidden = true // or whatever
}

代码片段 IndexPath(item: 0, section: indexPath.section) 可能看起来有点奇怪,但事实证明 supplementaryView 只在第一个返回部分中的项目。

关于objective-c - 如何重新加载 UICollectionView 补充 View (HeaderView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42107721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com