func configureDataSource() {
print("configure dataSource!!!")
dataSource = UICollectionViewDiffableDataSource
<Section, StoryItem>(collectionView: storyCollectionView) {
(collectionView: UICollectionView, indexPath: IndexPath, storyItem: StoryItem) -> UICollectionViewCell? in
print("try creating a collection view cell!")显示调用函数的print语句出现在控制台中,但{ for UICollectionViewDiffableDataSource中的代码不运行。
对下一步在哪里进行故障排除有任何建议吗?非常感谢!
发布于 2020-02-04 01:41:18
需要有更多的代码。您需要用一些数据填充不同的数据源。否则,集合视图中的项数为零,不需要生成任何单元格。
一个典型的舞蹈(通常在viewDidLoad中)会出现这样的情况:
// make the data source
self.datasource = UICollectionViewDiffableDataSource<String,String>(collectionView:self.collectionView) {
cv,ip,s in
return self.makeCell(cv,ip,s) // return cell
}
// give it a supplementary view provider if you have headers/footers
self.datasource.supplementaryViewProvider = { cv,kind,ip in
return self.makeSupplementaryView(cv,kind,ip) // return view
}
// give the data source some data (here, my data is sitting in `sections`)
var snap = NSDiffableDataSourceSnapshot<String,String>()
for section in sections {
snap.appendSections([section.0])
snap.appendItems(section.1)
}
self.datasource.apply(snap, animatingDifferences: false)https://stackoverflow.com/questions/60049380
复制相似问题