I assume that you want to define a model object represented by a button in a view. I was able to identify the model object by clicking on the buttons in the form of a collection. I could not use a selection index or any other similar attribute, but in the end, a model can be defined.
Assuming your NSArrayController already has your array, do the following:
Handcuffs:
Only one snap is required to view the collection.
Bind to: <NSArrayController instance> Controller Key: arrangedObjects Model Key Path: <blank>
Controller:
You must connect the controller to the content view.
property (weak) IBOutlet NSCollectionView *collectionView;
Finally, the controller receiving the message with the click of a button should implement this IBAction:
- (IBAction) collectionViewClick:(id)sender { id objectInClickedView = nil; for( int i = 0; i < [[self.collectionView content] count]; i++ ) { NSCollectionViewItem *viewItem = [self.collectionView itemAtIndex:i]; if( [sender isDescendantOf:[viewItem view]] ) { objectInClickedView = [[self.collectionView content] objectAtIndex:i]; } } }
An objectInClickedView will be assigned. If you are really interested in a view or viewItem, you can change the code.
Dave fn
source share