I ended up resolving this by setting cell.delegate = self in the dataSource handler where I connect the data source to my collection view in EmotionExplorerViewController.
// Create diffable data source
dataSource = UICollectionViewDiffableDataSource<Section, Item>(
collectionView: emotionExplorerCollectionView
) {
(collectionView, indexPath, item) -> UICollectionViewCell? in
// Return the appropriate cell based on the item type
switch item {
case .title:
return collectionView.dequeueConfiguredReusableCell(
using: titleCellRegistration,
for: indexPath,
item: item
)
case .main:
let cell = collectionView.dequeueConfiguredReusableCell(
using: mainCellRegistration,
for: indexPath,
item: item
)
cell.delegate = self
return cell
case .filter:
return collectionView.dequeueConfiguredReusableCell(using: filterCellRegistration,
for: indexPath,
item: item)
case .skeleton:
return collectionView.dequeueConfiguredReusableCell(using: skeletonCellRegistration,
for: indexPath,
item: item)
}
}
I also reverted to using my old cell registration method since the content configuration API was a bit tricky to set up and customise.
Topic:
UI Frameworks
SubTopic:
UIKit