0

I have the following requirement and struggle to implement it:

I have an NSTableView that is bound to an Array. One column of the table is a NSPopupButtonCell. Everything works with the NSPopupButtonCell writing data back to the underlying array and so forth.

The requirement is that if I have for example 10 rows selected and change the entry of the NSPopupButtonCell for one row, it should apply the same to all of the other selected rows.

I was trying to implement an event that would listen to when the NSPopupButtonCell changed value and then apply it to the rest of the selected items but no luck.

Do you have any suggestion how to solve this ? How can I listen to the NSPopupButtonCell change ?

thanks a lot.

Mozzak
  • 201
  • 3
  • 16

1 Answers1

1

What did you actually try?

It should work to simply use target-action. Connect the NSPopUpButtonCell's action to a target and selector. Most likely you would use the view controller or window controller as the target.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • I tried a similar approach. I created an IBAction and connected it to the `NSPopupButtonCell`. The strange thing is that the sender is actually the `NSTableView` and not the `NSPopupButtonCell` as I would have expected. It does fire correctly but don't know how to access it. Any ideas how to achieve this ? – Mozzak Jan 29 '15 at 01:35
  • Yes, the sender is always the *control* which contains the cell. With a button, for example, it's the `NSButton`, not the `NSButtonCell`. A table view is the control for its cells. Query the table's `clickedRow` (and, if needed, `clickedColumn`) to figure out which pop-up button cell was manipulated. – Ken Thomases Jan 29 '15 at 02:40
  • yes the `clickedRow` was the missing piece. I got it working. Thanks so much for your help. – Mozzak Jan 29 '15 at 03:10
  • actually i still have some issues. I can access the the `NSPopUpButtonCell` in my IBAction but the item shown as selected is the one before I changed the item in the list so it seems it has not flushed the actual selection. I do however need to know what was selected. Do you have another idea how to get the newly selected item ? thanks again. – Mozzak Jan 29 '15 at 03:56
  • You mean the item in the pop-up menu or the item in the table view? And how are you determining which is selected? Are you examining a model property, the array controller, or the pop-up button cell itself? – Ken Thomases Jan 29 '15 at 04:36
  • here is my IBAction: ` - (IBAction) handleActionDropdownSelection:(id) sender{ NSInteger row = [tableView clickedRow]; NSInteger col = [tableView clickedColumn]; // Get row at specified index NSTableColumn *selectedRow = [tableView tableColumnWithIdentifier:@"action"]; NSPopUpButtonCell* dropdown = [selectedRow dataCell]; Song* s = [list objectAtIndex:row]; } ` Here I tried both getting a hold of the NSPopupButtonCell as well as the data item bound. Both of them still show the value before changing the drop down. ideas? – Mozzak Jan 29 '15 at 12:44
  • The column's `dataCell` is a prototype, not necessarily the active cell. Try asking the table view for its `selectedCell`. Also, assuming `list` is the array which the array controller is using for its content, you need to access it through the array controller's `arrangedObjects` property. An array controller can present its arranged objects in a different order (and possibly filtered), so the row is not an appropriate index into `list`. – Ken Thomases Jan 29 '15 at 16:24