Re: TableColumn dataCell actions
Re: TableColumn dataCell actions
- Subject: Re: TableColumn dataCell actions
- From: mmalcolm crawford <email@hidden>
- Date: Sun, 10 Nov 2002 01:29:10 -0800
On Saturday, November 9, 2002, at 04:16 PM, Angela Brett wrote:
I have an NSTableView where one of the columns' dataCell is a
checkbox. Here is the code to set up the dataCell:
NSButtonCell *checkBoxCell = [[[NSButtonCell alloc] init] autorelease];
[checkBoxCell setButtonType:NSSwitchButton];
[checkBoxCell setTarget:self];
[checkBoxCell setAction:@selector(addOrRemoveTexture:)];
[checkBoxCell setTitle:@""];
[[textureTable tableColumnWithIdentifier:BRCSUseTexture]
setDataCell:checkBoxCell];
Then in addOrRemoveTexture: I have some code which looks at the
table's clickedRow to find out which checkbox was clicked and updates
the internal data accordingly. I have implemented
tableView:willDisplayCell:forTableColumn:row: to tick the checkbox if
necessary.
You're making things too difficult.
Set up the checkbox with:
NSButtonCell *checkBoxCell = [[[NSButtonCell alloc] init] autorelease];
[checkBoxCell setButtonType:NSSwitchButton];
[checkBoxCell setTitle:@""];
[[textureTable tableColumnWithIdentifier:BRCSUseTexture]
setDataCell:checkBoxCell];
Then simply implement the tableview datasource methods:
- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
and
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn row:(int)row
just as you would for other values. When the former is called, return
an NSNumber for 0 or 1, depending on the desired state of the checkbox
for that row. When the checkbox is clicked, the datasource will be
sent the latter message, and the object value will be an NSNumber
(well, NSCFBoolean, but)...
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.