layoutAttributesForItem(at indexPath:) never gets called on UICollectionViewLayout subclass

Hi!

I've got a custom UICollectionViewLayout which has its cells and two supplementary kind of views scattered all over randomly within its bounds. It should be a calendar month view with day of week labels on top, week numbers on the left (supplementary views) and day cells in the middle (items).

So far I tracked down that the layoutAttributesForItem(at indexPath:) and layoutAttributesForSupplementaryView(ofKind elementKind:, at indexPath:) are not getting called. Which gives them a reason not to be placed where they should be. layoutAttributesForElements(in rect: ) gets called indeed and the returned value is also OK:

        override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
    {
        super.layoutAttributesForElements(in: rect)
        var arr = [UICollectionViewLayoutAttributes]()
        arr.append(contentsOf: AllAttributes.filter({ (Item:UICollectionViewLayoutAttributes) -> Bool in
            (collectionView!.numberOfSections) > Item.indexPath.section &&
                rect.intersects(Item.frame)
        }))
        return arr //47 long array of UICollectionViewLayoutAttributes
    }

In IB the Collection View is specified to be Custom Layout and the respective subclass is specified there.

I inspected the official example code here: https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/layouts/customizing_collection_view_layouts The only diffrerence I see is that the example uses UICollectionViewController, which is specified to be Flow Layout in IB, and then the UICollectionView is re-instantiated in code as custom during viewDidLoad.

Could that really make a difference? This solution would not be too convenient for me, as I have also other controls on my Controller View.

Any help would be appreciated.