我有一个包含部分和开头的集合视图。我想在用户创建数据并在新部分中显示数据后添加一个新部分。这是我尝试过但失败的代码。运行代码后,新部分不会出现。
var snapshot = self.collectionView.diffableDataSource.snapshot()
let recentlySection = Section(title: "Recently Colored",
cells: [userPicture],
sectionType: .recentlyColored)
snapshot.appendSections([recentlySection])
snapshot.appendItems([userPicture], toSection: recentlySection)
self.collectionView.diffableDataSource.apply(snapshot, animatingDifferences: true)
self.collectionView.reloadData()
谢谢!