tags:

views:

25

answers:

2

Hi,
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?

+1  A: 

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.

Preston
Better yet, instead of dictionaries, make them model objects. http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ModelObjects/
Peter Hosey
Good advice. I assumed they were just interface elements because he said they were string literals.
Preston
You mean making both of the arrays custom objects with the array as a attribute?
Bakaburg
@Bakaburg One array of objects, dictionaries or otherwise, with two strings in each object that get bound to the two columns in your table.
Preston
A: 

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.

Graham Lee
I think you're right. I also noticed that I cannot make a binding from the column to the arrays in myController. I think the table-array controller binding is a specific not-general solution...
Bakaburg