问题描述
每个部分都有一个带有 supplementaryView 的uicollectionview. 在每个 supplementaryView 中,我都有一些按钮.在数据源方法 collectionView:viewForSupplementaryElementOfKind:atIndexPath:中,我正在使用 indexPath.section 设置按钮标签.当按下按钮时,我做了一些委托方法,并将section(button.tag)作为参数发送.
I have an uicollectionview with supplementaryView for each section. In each supplementaryView I have some buttons.In dataSource method collectionView:viewForSupplementaryElementOfKind:atIndexPath: I'm setting the buttons tags with the indexPath.section. I made some delegate methods when a button is pressed and send the section(button.tag) as parameter.
一切正常,但是问题来了:
Everything works fine, but here comes the problem:
- 当我插入或删除一个部分时,它必须更新按钮标签,但是我不想重新加载每个部分中的所有项目.
我尝试过:
- 使用dataSource方法 collectionView:viewForSupplementaryElementOfKind:atIndexPath:获取补充视图,并为每个 supplementaryView 调用 layoutIfNeeded 方法,这样 supplementaryViews 正在重新加载,但是这种方法使我的 supplementaryViews 倍增. 在 collectionView.subviews 中
- 一个快速的 for ,仅获取 supplementaryView 并调用 layoutIfNeeded 方法,但是不重新加载,仅重新加载布局.
- reloadSections:方法,但这会重新加载 部分中的所有项目
- to get the supplementaryViews with the dataSource method collectionView:viewForSupplementaryElementOfKind:atIndexPath: and call layoutIfNeeded method for each supplementaryView, in this way the supplementaryViews are reloading, but this approach multiply my supplementaryViews.
- a fast for in collectionView.subviews and get just the supplementaryView and call layoutIfNeeded method, but it doesn't reload, just the layout is reloading.
- reloadSections: method, but this reload all items from the section
哦.我使用 NSFetchedResultsController (委托)插入和删除节.
Ohh.. And I use NSFetchedResultsController(delegate) for inserting and deleting sections.
有人可以帮我吗?有没有办法只重新加载 supplementaryView ?在这种情况下还有其他方法吗?
Can anyone help me with this? Is there a way to reload only the supplementaryView? Is there other approach for this scenario?
谢谢!
推荐答案
要重新加载补充视图,可以使用-invalidateLayoutWithContext:
.
To reload supplementary views you can use -invalidateLayoutWithContext:
.
请参见UICollectionViewLayoutInvalidationContext
和方法-invalidateSupplementaryElementsOfKind:atIndexPaths:
的文档(自iOS 8起可用).
See documentation for UICollectionViewLayoutInvalidationContext
and method -invalidateSupplementaryElementsOfKind:atIndexPaths:
(available since iOS 8).
这篇关于UICollectionView:是否有一种方法可以仅重新加载补充视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!