tags:

views:

288

answers:

5

I need to know when the user finishes editing a cell in an NSTableView. The table contains all of the user's calendars (obtained from the CalCalendarStore), so in order for the user's changes to be saved I need to inform the CalCalendarStore of the changes. However, I can't find anything that gets called after the user finishes their editing - I would guess that there would be a method in the table's delegate, but I only saw one that gets called when editing starts, not when editing ends.

A: 

Look into the NSTableDataSource protocol. The message you are looking for is called: tableView:setObjectValue:forTableColumn:row:

Lounges
A: 

That doesn't seem to work in my case. I set my controller class as the DataSource to the table, but the method was never called. The data is my table is bound to the values in an NSArrayController - could that be why my object was not called?

Andy
+1  A: 

Set up observers for each item in the content array using addObserver:toObjectsAtIndexes:forKeyPath:options:context:

You will also need to set an observer for the array itself, so that you will be notified about objects that are added to or removed from the array.

For an example look at the iSpend project.

Nathan Kinsinger
+3  A: 

Subclass NSTableView and override textDidEndEditing: (be sure to call super's implementation).

This will only be invoked by text fields NSTextFieldCell or NSComboBoxCell (but only when changing the value by typing it, not by selecting the value from the combo's menu).

Nathan Kinsinger
That looks like it will work. Thank you very much. :)
Andy
A: 

Subclass NSArrayController and override objectDidEndEditing: (be sure to call super's implementation).

This will mostly only be invoked by text fields NSTextFieldCell or NSComboBoxCell (but only when changing the value by typing it, not by selecting the value from the combo's menu). There may be a few other cells that will invoke it, but I'm not sure which ones. If you have a custom cell then consider implementing the NSEditor and NSEditorRegistration informal protocols.

Nathan Kinsinger