Bindings & Checkbox in NSTableView
Bindings & Checkbox in NSTableView
- Subject: Bindings & Checkbox in NSTableView
- From: Steven Huey <email@hidden>
- Date: Tue, 6 May 2008 15:31:38 -0400
Hi,
I want to bind the value of a checkbox in a column of a NSTableView to
a custom object managed by an NSArrayController. I have the
NSArrayController setup to manage a class I've created using Obj-C 2.0
properties, and added keys in the IB inspector for the
NSArrayController to match the properties of my class. I've bound the
value of the columns in my NSTableView to my array controller using
arrangedObjects.keyName. The column containing checkboxes is bound to
a property that is backed by a NSNumber instance.
Everything is working fine except clicking on the checkboxes doesn't
change the value in my custom class, and my checkboxes are always "on"
since by default the property they are bound to is initialized with
[NSNumber numberWithBool:YES]. Other columns that use the default text
cell and that are bound to NSString properties work fine.
My custom class is defined as:
@interface Foo : NSObject {
NSNumber *active;
NSString *description;
}
@property(copy) NSNumber *active;
@property(copy) NSString *description;
@end
@implementation Foo
@synthesize active, description;
- (id)init
{
if (self = [super init]) {
self.active = [NSNumber numberWithBool:YES];
self.description = @"Untitled";
}
return self;
}
@end
I set the table column to use a checkbox using:
NSButtonCell *cell = [[NSButtonCell alloc] init];
[cell setButtonType:NSSwitchButton];
[cell setImagePosition:NSImageOnly];
[cell setControlSize:NSSmallControlSize];
[[myTable tableColumnWithIdentifier:@"active"] setDataCell:cell];
Any ideas on what I'm missing or how better to debug this?
Thanks,
Steve
--
Steven Huey Software - http://www.stevenhuey.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden