Greetings.
I am attempting to set up an NSTableView with two columns, to represent a simple key-value store backed by two NSMutableArrays.
Each of the arrays has an NSArrayController associated with it, and each of the columns is bound to one of the array controllers. However, when I add elements to each array, using the array controllers' "add()" method, the table shows only one value in both columns.
With quite a bit of poking around (the full extent of which I fear I cannot recall), I was able to get it to change which value it displays in both columns, but I could not get it to display a different value in each column. NSLog() confirms that the correct values are being added to the arrays, so it's clearly a display issue of some sort.
I've even created a table, array, and array controller purely for testing, and while the second table will display my test array's value properly, once I add a second column to the test table, bound to the first original array, both columns of the table show the test array's value.
I can't help but feel that I'm just making some stupid mistake, as this is the first time I've used a simple NSArrayController binding to populate a table.
Any assistance would be most appreciated.
Timothy Collett
It sounds like this is a cell-based table view ("each of the columns is bound to …"). If that is so, there's a little bit of secret sauce that we normally don't think about. It's the table view that has a content binding to the array controller, not the columns. Normally, you specify the columns as if they are bound all the way through to the model, but the first such binding (according to the documentation) also sets the table content binding (and, I assume, the table view massages the binding between it and the column to be relative to its own bound content).
That means you can't bind different columns to different content — which gets bound first will "win". Instead, you'll need a single array of objects that have 2 properties, one for each column.
But, really, don't use cell-based table views any more. Go with view-based table views. (If you've done that already, then ignore all this.)
I strongly suggest you create a custom class to represent the data displayed in each row. This can be part of your data model, if that makes sense, or it can be purely local to your window/view controller if objects of this class are used only for display. Store one array of these objects instead of two arrays. (If you have a need for two arrays for other reasons, you can create a derived indexed property (i.e. array) on your window/view controller that packages the two values together as necessary, without the need to store the values again. The trick here is to ensure that the derived property is properly KVO compliant.)