0

I have an UICollectionView with a custom layout to display something similar to a Gantt chart. A decoration view is used to add a timeline across the top of the collection view. I need to pass along an NSDate to the decoration view for display purposes, but I'm not really sure how to correctly do so. The Apple docs say that it shouldn't be tied to the data source, which it's not really, but I need to give the decoration view some additional context. Here's what I'm wondering:

  • What is the appropriate way to pass additional context (parameters/arguments) to a decoration view? Custom UICollectionViewLayoutAttributes subclass with an added NSDate property?
  • Is this just a misuse of a decoration view at this point? Should I be using a supplementary view instead?
chinabuffet
  • 5,278
  • 9
  • 40
  • 64

1 Answers1

0

That sounds like an excellent use of a decoration view. Your approach of subclassing UICollectionViewLayoutAttributes to add a date property makes sense for passing that context between your layout and the decoration view itself. The final step is to add something like a date property to your custom layout. When that property changes, you'll want to invalidate the layout (ideally just the decoration view using -invalidateLayoutWithContext:) so that your decoration view gets a chance to apply the new attributes.

The point of decoration views is that the collection view itself doesn't know or care that they exist. I understand the struggle in this case, because the visible date range is related to the data in the collection view, but I think a decoration view is entirely suitable here.

nolanw
  • 475
  • 2
  • 14