Slide 14
Slide 14 text
ViewControllerにおけるCell要素構築処理の概要
CellRegistrationを利用したCellの生成処理の例
private func configureTopDataSource() {
let topBannerCellRegistration = TopBannerCell.makeCellRegistration()
let topFeaturedCellRegistration = TopFeaturedCell.makeCellRegistration()
…(表示する必要がある分だけCellRegistrationを追加する)…
topDataSource = TopDataSource(collectionView: collectionView) { [weak self] (collectionView, indexPath, itemType) -> UICollectionViewCell? in
guard let self = self else { return UICollectionViewCell() }
switch itemType {
case .banner(let bannerViewObject):
let cell = collectionView.dequeueConfiguredReusableCell(using: topBannerCellRegistration, for: indexPath, item: bannerViewObject)
return cell
case .featured(let featuredViewObject):
let cell = collectionView.dequeueConfiguredReusableCell(using: topFeaturedCellRegistration, for: indexPath, item: featuredViewObject)
return cell
…(表示する必要がある分だけCell生成処理を追加する)…
}
}
}
private var topDataSource: TopDataSource!
topDataSource.supplementaryViewProvider = { … } を利用する形になります。
ViewController側におけるCell生成処理の抜粋 :
※ Header/Footer要素の構築に関して:
※ViewModel内にもDataSourceのインスタンスを渡しておく(viewDidLoad時)
① 表示に必要なCellRegistrationの準備
② CellRegistrationとItemTypeを利用したCell生成処理