Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NSCollectionView without bindings

Is there a way to use an NSCollectionView without bindings?

like image 865
Radu Paise Avatar asked Mar 12 '11 10:03

Radu Paise


1 Answers

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 copying 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/inited one of these custom collectionViewItems and set it as the collectionView's itemPrototype. NSCollectionView did the rest.

like image 55
Dave DeLong Avatar answered Oct 21 '22 10:10

Dave DeLong