Skip navigation.
 
mlRe: TableColumn dataCell actions
FROM : mmalcolm crawford
DATE : Sun Nov 10 10:29:10 2002

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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlTableColumn dataCell actions Angela Brett Nov 10, 01:16
mlRe: TableColumn dataCell actions mmalcolm crawford Nov 10, 10:29
mlRe: TableColumn dataCell actions Yann Bizeul Nov 10, 12:32
mlRe: TableColumn dataCell actions Angela Brett Nov 11, 10:36
mlRe: TableColumn dataCell actions Angela Brett Nov 15, 09:54