views:

381

answers:

4

i have NSTableView bound to an NSArrayController. in my model i have a BOOL field. i'm trying to bind that value to the column. it displays correctly (1 where value is YES and 0 where value is NO), but it's readonly. =( when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. column is editable.

i can successfully bind it with IB -- i just bind it as usual and all works. but i can't do the same programmatically =(

that's how column is created and added:

NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"ok"] autorelease];
[column setEditable:YES];
[[column headerCell] setStringValue:@"OK"];
[column bind:@"value" toObject:self.arrC withKeyPath:@"arrangedObjects.ok" options:nil];
[table addTableColumn:column];

i have a problem only with BOOL values, if i bind the same column to some other field (just changing keyPath) all works fine.

A: 

You need to bind the table column, not the cell.

Peter Hosey
sorry, i didn't describe it well enough. actually, i'm binding column. the problem is only with BOOL values -- string and integer values are working correct..
Vyacheslav Karpukhin
In that case, please edit your question to include a screenshot of the Bindings inspector with the column selected.
Peter Hosey
the problem is, that i can make it work with IB without any problems. but i can't make it work if i create column and add it to the table at the runtime process -- it works with other fields, but doesn't work with BOOL fields.
Vyacheslav Karpukhin
In that case, please edit your question to include the code you're using to create, add, and bind the table column.
Peter Hosey
done. .
Vyacheslav Karpukhin
+1  A: 

it's readonly =(. when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. column is editable.

And then, in your code snippet:

[column setEditable:NO];

Your column is not editable. That's why editing doesn't work. Change NO to YES.

By the way: Is there a reason you're displaying this value as text and not a checkbox?

Peter Hosey
originally it was YES.. don't know how it ended up with NO. anyway -- doesn't help. problem is not there. i can access editor after double click, but can't submit value.
Vyacheslav Karpukhin
A: 

What is bound to arrC which I am assuming is your array controller?

Is arrC bound to an array? What's are the objects in the array bound to the controller? Coredata entities? NSMutableDictionaries?

Jeff Hellman
arrC bound to an array. in the array -- entitites of my own class.
Vyacheslav Karpukhin
Do your own entities have a "setOk:" method (or is "ok" a readwrite property)?
Pascal
A: 

You need a value transformer, specifically NSNegateBooleanTransformerName. Google for Apple's "Value Transformer Programming Guide"

Elise van Looij
why i don't need it if i use IB to bind the column?
Vyacheslav Karpukhin