Radu Paise Radu Paise - 1 year ago 184
Objective-C Question

Using NSCollectionView without bindings

Is there a way to use an

without bindings?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download