Hi
If anyone still having same problem, try this:
In my case I faced the problem when I was using list layout
I changed my code from this:
private func createListLayout() -> UICollectionViewLayout {
var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
config.backgroundColor = UIColor.white
config.headerMode = .supplementary
let layout = UICollectionViewCompositionalLayout.list(using: config)
return layout
}
To this code:
private func createListLayout() -> UICollectionViewLayout {
let layout = UICollectionViewCompositionalLayout() { sectionIndex, layoutEnvironment in
var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
config.backgroundColor = UIColor.white
config.headerMode = .supplementary
let section = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment)
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(144))
let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: headerSize,
elementKind: "myElementKind", alignment: .top)
section.boundarySupplementaryItems = [sectionHeader]
return section
}
return layout
}
And this is my provider if you need:
dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in
let header = collectionView.dequeueReusableSupplementaryView(
ofKind: "myElementKind",
withReuseIdentifier: "myIdentifier",
for: indexPath) as! MyCustomHeader
// code
return header
}
This worked for me
I hope this works for you as well.
Best regards.