简体   繁体   中英

NSTableColumn bound to a BOOL value

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.

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?

您需要绑定表列,而不是单元格。

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM