Hello. I have a table view bound to an array controller. On app launch, I present an OpenPanel and then set the array to the names of the files returned.
The table has a single column, which is set to editable.
I wish to edit the cell values directly by double-clicking the table, however it will not allow me to do so. The error returned is:
[<NSPathStore2 0x200044d60>setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key.
Basically, I need to update the array with the new text entered. I am temporarily working around it by displaying a dialog on double-click and setting the array item to the returned value. This works, but is a bit inelegant. I would like to be able to directly edit in the table itself.
Your problem is here: “setValue:forUndefinedKey”, which means some bindings (or some properties) aren’t correctly defined. Could you post your code? It hard to say what’s going wrong only with your idea.
To be able to edit table view cells bound to an array controller the array controller expects key value coding compliant objects (default NSMutableDictionary). NSString or the abstract private NSPathStore2 is not key value coding compliant.
So create NSMutableDictionary objects from your array and bind the key path of the table view cell to the key of the dictionary
I’m very new to ASOC and still rely on existing code to integrate into my own. I understand what I need to do with the binding, but I don’t know how to create an NSMutableDictionary from the array. Could you help me define it as a property and then assign the array to it?
something like this, myArray is the list of filenames and arrayController is the instance of the NSArrayController
set myArray to {"alpha", "beta", "gamma"}
repeat with anObject in myArray
arrayController's addObject_(current application's NSMutableDictionary's dictionaryWithObject_forKey_(anObject, "name"))
end
Once you have transformed your array (AS list) into a list of NSMutableDictionaries (AS records) you bind the tableView to your controller, with controller key = arrangedObjects and key path = name (to follow Stefan’s example).
Be cautious about URL path vs NSStrings. There are methods to convert each one to the other.
Thanks guys. I still I can’t get it to work though. The table is blank.
I have an Array Controller, whose Content Array is bound to the App Delegate. Controller Key is empty and Model Key path is tableArray
The Table View’s Table Column (there is only one), is bound to the Array Controller’s Value. Controller Key is arrangedObjects. Model Key Path is name.
tableArray is defined in the script as:
property tableArray : {}
I use the script you provided to initialize the NSMutableDictionary:
set myArray to {"alpha", "beta", "gamma"}
repeat with anObject in myArray
tableArray's addObject_(current application's NSMutableDictionary's dictionaryWithObject_forKey_(anObject, "name"))
end repeat
But nothing happens. Am I doing something wrong or am I missing something, or both?