I'm using an NSCollectionView
to display various objects. The whole things works rather well, except for one annoying thing. I cannot figure out how to access the various controls on the view used to represent each object in the collection.
Here's the setup:
- I have dragged an
NSCollectionView
into my view in IB. - I made a custom subclass of
NSCollectionViewItem
. Mapped my class in IB. - I made a custom subclass of
NSBox
to act as the view for each object in the collection. Also mapped this class in IB and connected it to theview
property of myNSCollectionViewItem
subclass. - I made all the bindings in IB to display the correct information for each object.
The view:
The resulting collection view:
Reasoning that that my subclass of NSCollectionViewItem
is basically a controller for each view in the collection, I made referencing outlets of the various controls in the view in my controller subclass:
@interface SourceCollectionViewItem : NSCollectionViewItem
@property (weak) IBOutlet NSTextField *nameTextField;
@property (weak) IBOutlet NSTextField *typeTextField;
@property (weak) IBOutlet RSLabelView *labelView;
@property (weak) IBOutlet NSButton *viewButton;
@end
When I inspect any instance of SourceCollectionViewItem
in the debugger, all the properties show up as nil despite the fact that I can actually see them on my screen and that everything is displayed as it should be.
My setup was inspired by Apple's sample app IconCollection.
I am obviously missing something. What?
EDIT: I found various posts hinting at a similar issue: CocoaBuilder.com and this question on SO.
EDIT: Just to be complete: this post deals with the subject as well and delivers a solution based on a combination of the options mentioned in the accepted answer.