Using NSCollectionView without bindings

Is there a way to use NSCollectionView without bindings?

+8
objective-c cocoa cocoa-bindings nscollectionview
source share
1 answer

Yes, and you do not need to subclass it.

You can use the content property to provide an NSCollectionView and an array of objects. For each of these objects, the collection view will produce a new NSCollectionViewItem on copy with its itemPrototype and set its representedObject property to the corresponding element in the content array.

So what I did when I did this was to subclass NSCollectionViewItem , and then override its setRepresentedObject: method to get a new object, forward it to super , and then set collectionViewItem accordingly. No subclasses of NSCollectionView . (But don't forget to implement -copyWithZone: ). I just alloc/init edited one of these custom collectionViewItems and set it as collectionView itemPrototype . NSCollectionView .

+15
source share

All Articles