swift UI集合视图:仅删除特定电池的隔板

33qvvth1  于 2023-03-22  发布在  Swift
关注(0)|答案(1)|浏览(110)

我需要显示UICollectionView中每个单元格的分隔符,除了一个部分的每个第一个单元格。我使用列表布局。到目前为止,我只能使用configuration.showsSeparators = false删除所有分隔符。
我的UICollectionView配置:

let collectionView: UICollectionView = {
    let provider = { (_: Int, layoutEnv: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
        var configuration = UICollectionLayoutListConfiguration(appearance: .grouped)
        configuration.showsSeparators = true // <----- shows separators for every cell
        configuration.footerMode = .supplementary
        return .list(using: configuration, layoutEnvironment: layoutEnv)
    }
    let listLayout = UICollectionViewCompositionalLayout(sectionProvider: provider)
    return UICollectionView(frame: .zero, collectionViewLayout: listLayout)
}()

小区注册:

let cellRegistration = UICollectionView.CellRegistration<MailboxCell, MailAccount> {
    (cell, indexPath, listItem) in
    // some setup code
}

dataSource = UICollectionViewDiffableDataSource<Account, ListItem>(collectionView: collectionView) { 
    (collectionView, indexPath, listItem) -> UICollectionViewCell? in

    // some setup
    return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: listItem)
}
0g0grzrc

0g0grzrc1#

一个可能的解决方案是通过设置configuration.showsSeparators = false来删除默认分隔符,然后在单元格UI的底部添加一个行视图来创建分隔符的假象。

相关问题