swift - 重新加载 UICollectionView viewForSupplementaryElementOfKind 而不重新加载 cellForItemAt
问题描述
我只想重新加载footerView。如果我使用 reloadData(),整个 collectionView 都会重新加载。
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionView.elementKindSectionHeader:
if let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: MockupCollectionHeader.className, for: indexPath) as? MockupCollectionHeader {
headerView.configure()
headerView.titleLabel.text = baseLayout.properties?.titleString
return headerView
}
return UICollectionReusableView()
case UICollectionView.elementKindSectionFooter:
if let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: MockupCollectionFooter.className, for: indexPath) as? MockupCollectionFooter {
footerView.configure()
footerView.footerLabel.text = baseLayout.properties?.footerBody
footerView.continueButton.addTarget(self, action: #selector(continueClicked(_:)), for: UIControl.Event.touchUpInside)
footerView.checkButton.addTarget(self, action: #selector(checkboxClicked(_:)), for: UIControl.Event.touchUpInside)
footerView.isChecked = baseLayout.isCheckbox
return footerView
}
return UICollectionReusableView()
default:
assert(false, "Unexpected element kind")
}
return UICollectionReusableView()
}
解决方案
推荐阅读
- java - 如何存储 Hash Map 值(如果值重复)?
- javascript - CodeSnippet 从右到左显示问题
- curl - Is there a way to compile cURL and all deps to a specific directory?
- r - 在R中将一系列pdf文件转换为gif
- mysql - SQL:如何从一个表中选择最大值,从另一个表中选择其他数据
- c - 为什么我不能将函数返回分配给矩阵元素?
- java - 自定义反序列化器来解析复杂的 Json
- javascript - 异步/等待事件流 mapSync 不起作用
- python - 在 x 轴上带有时间的 Matplotlib 图中,如何使长轴和短轴标签不重叠?
- python - 如何修复分数加法失败