我有一个 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 上的开关
关于ios - 如何在 UICollectionView 中分割部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55641573/