ios - 如何拆分 UICollectionView 中的部分?
问题描述
我有一个 UICollectionView,它实现了按部分组织的页面。我想将一个部分分成两部分并具有以下逻辑。但 UICollectionView 似乎对此并不满意:
func splitSection(at index: IndexPath) {
// this performs the logical split
self.document.splitSection(at: index)
if let cv = self.collectionView {
cv.performBatchUpdates({
let N = self.document.numberOfSection
let n = N - index.section - 1
let range = Range.init(uncheckedBounds: (index.section, n))
let affectedSections = IndexSet.init(integersIn: range)
cv.reloadSections(affectedSections)
let sections = IndexSet.init(integersIn: Range.init(uncheckedBounds: (N-1, 1)))
cv.insertSections(sections)
}, completion: { (_) in
// commit section updates
})
}
}
解决方案
在 numberOfSections 函数中返回 2 然后在 cellforitemat 函数中使用 indexpath.section 上的开关
推荐阅读
- python-3.x - 如何使用 scapy 在 LDP 层中设置可选参数
- awk - 从特定字符串重新排列到相应的列
- android - 未找到实现
- linux - python将输入从shell截断为特定数字
- php - 如何让查询忽略我的搜索引擎中的空搜索字段
- javascript - 如何在屏幕上显示输入值?
- python-3.x - pip install -r 文件中的所有依赖项,除了一个
- python - 在 python 上的 JayDeBeAPI 中设置 JAVA_HOME
- javascript - 浏览器或窗口关闭后清除 cookie
- log4j - maximumFileSize (Log4Net) 和 MaxFileSize (Log4J) 的规范