确定NSCollectionViewCompositionalLayout

我正在尝试使用NSCollectionViewNSCollectionViewDiffableDataSource创建具有动态数目的节的NSCollectionViewCompositionalLayout

收集视图用于显示搜索结果,部分的数量取决于找到的结果的类型和数量。每个部分使用不同的布局显示其内容类型。

数据源被声明为NSCollectionViewDiffableDataSource<String,SearchResult>,其中SearchResult是使用Hashable实现UUID()的类。结果为零的部分不是空的,而是在集合视图中不存在。

我遇到的困难之一是确定与布局sectionIndex中的sectionProvider对应的段标识符:

private func createLayout() -> NSCollectionViewLayout {
    let sectionProvider = { (sectionIndex: Int,layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection in
        // How can the section identifier corresponding to `sectionIndex` be determined?

        // Create a `NSCollectionLayoutSection` appropriate for the section type
        let section = NSCollectionLayoutSection(/* ... */)
        return section
    }
    return NSCollectionViewCompositionalLayout(sectionProvider: sectionProvider)
}

由于收集视图的部分数目取决于搜索结果,因此0部分中显示的项目类型可能会更改。

有关示例项目,请参见https://github.com/sbooth/DiffableTest

zhtang0526 回答:确定NSCollectionViewCompositionalLayout

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3128015.html

大家都在问