I am struggling with a design issue: I have an NSCollectionView
that contains several items (it's binded to an NSArrayController
which is, in turn, binded to a NSManagedObjectContext
). I have decided to draw the view for each single item programmatically, mainly because I noticed that nesting several NSView
s inside the Item View creates performance issues when there are more than a certain number of items in the collection view.
Consider the following hierarchy: NSCollectionView
=> NSCollectionViewItem
-> NSView
. (The default one used by NSCollectionView
).
My custom NSView
contains several layers, some are CATextLayer
s, others are regular CALayer
s, and they all animate together (within the same CATransaction
) whenever they need to. The issue here is that each CALayer
needs to display the content of some data which is accessible through the representedObject
property of the NSCollectionViewItem
... which owns the NSView
!
I have two options (probably many more, I'm more than open to suggestions):
- I replicate the representedObject
from the NSCollectionViewItem
to its NSView
, and I keep it consistent througout the execution of the program. I don't really like this one.
- I expose the CALayer
s in the NSView
, and I set their content/string from within the NSCollectionViewItem
's setRepresentedObject:
method. I like this one better, because there is no data saved in the NSView
(except for that which is being shown by through the layers, of course).
Am I wrong? Is there a more elegant solution?
Thanks in advance, I really apreciate the help. Cheers
Gian Marco