NSCollectionView layout implementing dynamic item heights on macOS 13.6
I need some guidance on Quick question that's been bugging me - I'm working on a personal project and I'm working with a question with NSCollectionView in macOS 13.6 where the items aren't resizing correctly when I change their heights dynamically... I have set the collection view to use a custom layout subclass of `NSCollectionViewFlowLayout`, and I've overridden the `layoutAttributesForElements(in:)` method to provide the correct attributes for each item based on their content size. However, when I update the height of any item and call `invalidateLayout()`, the items do not reflect their new sizes as expected. Here's the relevant part of my layout code: ```swift override func layoutAttributesForElements(in rect: NSRect) -> [NSCollectionViewLayoutAttributes] { let attributes = super.layoutAttributesForElements(in: rect) for attribute in attributes { if let itemIndex = attribute.indexPath.item as Int?, let newHeight = self.delegate?.collectionView(self.collectionView, heightForItemAt: itemIndex) { attribute.size.height = newHeight } } return attributes } ``` Despite this, the item sizes appear to be exploring at their initial height. I've also tried calling `collectionView.reloadData()` after changing heights, but this doesn't seem to help either. The debug output shows the new heights are computed correctly, but visually, the collection view items remain unchanged. Could there be something Iām missing regarding the layout invalidation or the way I'm updating the item height? Any insights would be greatly appreciated. I'm working on a application that needs to handle this. What am I doing wrong? Any examples would be super helpful. I'm working on a desktop app that needs to handle this. Any advice would be much appreciated.