Is there a way to use an NSCollectionView
without bindings?
Yes, and you don't need to subclass it.
You can use the content
property to give the NSCollectionView
and array of objects. For each one of those objects, the collection view will manufacture a new NSCollectionViewItem
by copy
ing its itemPrototype
and setting its representedObject
property to the corresponding item in the content
array.
So what I did when I did this was to create a subclass of NSCollectionViewItem
and then overrode its setRepresentedObject:
method to receive the new object, forward it on to super
, and then customize the collectionViewItem appropriately. No subclassing of NSCollectionView
was required. (But don't forget to implement -copyWithZone:
!) I simply alloc/init
ed one of these custom collectionViewItems and set it as the collectionView's itemPrototype
. NSCollectionView
did the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With