Search code examples
objective-cnsarraycontrollernscollectionviewnscollectionviewitem

NSCollectionViewItem button always returns first item from ArrayController


I have an NSCollectionView with NSArrayController bound to NSCollectionViewItem.

The Item itself contains button (the whole space of Item).

When the button clicked I'm trying to determine on which item button was clicked, but can't:

[[mineArrayController selection] valueForKey:@"name"];

always returns first item's name.

What can I do to determine which item's button was clicked?


Solution

  • My problem was solved with this answer:

    Get the representedObject values of NSCollectionViewItem NSButton click

    You need to bind Represented Object of Button Cell to Collection View Item and get your object from code like this:

    YourModel *selectedItem = [[[sender cell] representedObject] representedObject];