views:

244

answers:

1

I'm really having trouble getting a Cocoa Table View cell to send action messages.

At the most basic level, in IB there is an action assigned for the NSTextViewCell object, and after editing and pressing Return nothing happens.

So I have an IBOutlet hooked up to the NSTextViewCell, and have been experimenting with NSActionCell messages to it. But the Table View seems to pretty much just ignore them.

I've also tried subclassing NSTextViewCell, but the methods I'm seeing all look like they want to pass values to the object from somewhere, not return a value from inside the object to configure its behavior.

I'm pretty new to programming and Cocoa -- can someone explain each thing that needs to be overridden and how and where to do it?

+2  A: 

AFAIK, the cells in an NSTableView won't send action messages out to your application, they're sent to the NSTableView so it can update its data. NSTableView itself tries to be pretty clever and update your data directly, rather than just telling you something changed, so depending on what you're trying to do and what the data source for the table is, you have a few options.

If you're using an NSTableViewDataSource object to populate the table, it's simple; just implement tableView:setObjectValue:forTableColumn:row: and the NSTableView will call that every time something is edited.

If you're using Cocoa data binding (for example, using an NSArrayController to bind an array of objects to the table,) then as long as everything is wired up correctly, the data should just automagically get updated in the source objects when the table is edited. If you need to take special action, then you can do whatever you need to in the property setter of your data class.

Will Goring
Actually, *some* cell types do have their action messages passed out to the application (the ones with buttons in them, mainly,) but even then, they're actually being responded to and re-sent by the table, as you can see by looking at the sender of the message in your handler.
Will Goring
What Will said about using `tableView:setObjectValue:forTableColumn:row:`!
Wevah
Thanks -- I think for practical purposes that will do.