Checkbox in NSTableColumn

kainjow

Registered
I need to be able to have one of the columns in my TableView have a checkboxes in it. How do I do this? I've looked all over the documentation and can't figure it out. I know it has something to do with NSTableColumn, NSButtonCell, NSCell, and the column's identifier. Could somebody give me the code to do this?

Thanks a lot!
 
i admit, it's a bit tricky the first time. but it all makes perfect sense:

first, you want to set up your table so that it "knows" what kind of data to show...

in you awakeFromNib, do something like this:

Code:
    NSButtonCell *dataCell;
    NSTableColumn *column;
	...
    column = [myTable tableColumnWithIdentifier:@"identifierForColumnWithCheckboxes"];
    dataCell = [[NSButtonCell alloc] init];
    [dataCell setButtonType:NSSwitchButton];
    [dataCell setTitle:@""];
    [dataCell setAlternateTitle:@""];
    [dataCell setBordered:NO]; 
    [dataCell setImagePosition:NSImageOnly];
    [dataCell setEditable:YES]; // or NO; whatever you need.
    [dataCell setControlSize:NSSmallControlSize]; //optional
    [column setDataCell:dataCell];
	...

now, the really tricky part is providing data. "tableView:eek:bjectValueForTableColumn:row:" expects an object to be returned; bool values are no objects. so instead, either return [NSNumber numberWithBool:YES] or [NSNumber numberWithBool:NO].

of course, "tableView:setObjectValue:forTableColumn:row:" will also hand you an nsnumber.

hope that helps.
 
Hey, thanks a lot for that seb2! I also needed that information, and it worked!!!
 
Back
Top