ios - 如何在 UICollectionView 中分割部分?

标签 ios swift 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 上的开关

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

相关文章:

ios - didSelectRowAt 上的图像没有变化

ios - 我想从 CoreData 获取数据,如果数据存在我想返回 true,如果不存在我想返回 false

swift - 当新的子/节点/监听器添加到 Firebase 连接时,如何获取 Firebase 消息?

ios - UICollectionViewCell 阴影导致小延迟

ios - 如何处理 UICollectionviewCell 或 UITableViewCell 内的按钮触摸

使用 NSURLSession 的 iOS FTP 上传

ios - 内存堆积,在ViewController之间切换,什么是ok的?

ios - 如何在 UITableView 中找到屏幕中心的哪一行/单元格?

ios - 尝试将变量从一个类移动到另一个类

ios - NSInternalInconsistencyException',原因 : 'Invalid update: invalid number of items in section 1 - While having multiple Sections