0
votes

For a View Based NSTableView/NSarrayController: how would I use the "action invocation" from a NSButton inside a tableCellView to change an attribute for an entity?

I have the following setup:

  • A "View Based" NSTableview with one column.
  • A NSarrayController which uses "entity mode" and is bound to core data entity.

Picture of the demo application

I would like to use the action invocation from the push button to update the entity. For example to set a "bool" attribute to true.

If I simply use the "model key path" and set it to objectValue.escaped the button is disabled.

2
Or should I use "sent action" ? Or forget nsarraycontrol and use a datasource?Rudi Rüssel
If I use "sent action" to a delegate(for example "petEscaped:") , I only get the sender id (the button)). Since the row is not selected (strange Isn't it) I have no chance to find and access the entity.Rudi Rüssel
The best SDK example I have found for my problem is TableViewPlayground where a button in an OutlineView is used. To my horror a "self-made" control with a data-source binding is used in this example. This would result in about 1000 lines of additional code only for UI handling (aggregated from the demo) and another control class for core-data handling.Rudi Rüssel
Im using a tableView delegate with a IBAction to handle the button and rowForView: and itemAtRow: to read the row data. (Like in the TableViewPlayground example)Rudi Rüssel

2 Answers

1
votes

I was able to get this to work by having an action set on the button itself (the view class inside the NSTableCellView), and then setting the delegate of the NSTableView to the class that implements the selector. It'd then work as expected.

0
votes

To clarify my question:

If I have another client for my data-source, connected for example via web-service and I want to trigger an event. I would use an entity-attribute to inform the client. Therefore I added a pushbutton to the tableCellView.

I started with a NSTableView and a NSArrayController connected to a core-data entity as object controller. Text-Fields, images, check-boxes and popup-buttons worked immediately after they were bound to the control. But I found no workable solution to bind a "Push-Button".(I tried to subclass the control, the table, the cell-view and the button without success.)

Finally I switched to the action/delegate method. With the methods rowForView:, itemAtRow: and representObject: it was possible to modify the attribute of the entity.

I'm not happy with this inelegant solution (outlineView/detached code). If there IS a solution with the arrayControl please let me know.