1
votes

I'm trying to understand cocoa bindings, but I found a problem that I'm really not able to understand.

I've got a really simple application in which you have a table with two columns and I want to bind this two columns to myController object that has two NSArray of literal string objects.

So I created two NSArrayController and bound each to one of the two arrays in myController. Then I bound the table columns to each NSArray using as Model Key Path: description, as Controller Key: arrangedObjects, and as Class Name: NSString.

The result is indeed strange: in the second column everything is okay, but in the first I got only a "(" and for every value of the first column.
Even stranger if I unbind the second column, the first starts to work well.

I tried to create two different table and bind their columns to the respective NSArrayController, and then it works.

So my impression is that the columns in the same table interact is some sort of way.
Any idea?

2

2 Answers

1
votes

It sounds like what you've got in the first column is actually a description of an array (which looks like):

(
"firstValue",
"secondValue",
 ...
"nthValue"
);

I can't think that I've read any documentation saying you can't bind different tablecolumns to different array controllers (and couldn't find any just now), but I can see why it might not work. At some point, the table view itself needs to know how many rows there are, which rows are selected and related information - binding to more than one array controller means that there could be more than one answer for each issue. So that means that it's reasonable to assume you can only have one array controller per table view, even if there's nothing to stop you setting up more.

1
votes

You're trying to use more than one data source for a single table. Instead, use one array controller and turn your two arrays into one array of dictionaries, each of which has two strings. Then, bind each table column to the respective dictionary keys.