Re: custom view in NSTableView
Re: custom view in NSTableView
- Subject: Re: custom view in NSTableView
- From: Brian Hill <email@hidden>
- Date: Sat, 11 Aug 2001 10:14:53 -0500
On Saturday, August 11, 2001, at 09:36 AM, email@hidden wrote:
I want to add a switch button to one of the columns in the
NSTableView, I mean each row of the table will have a switch
button ([NSButton setButtonType: NSSwitchButton]) for that
particular column. How should I change my data source to send a
NSSwitchButton for that particular column. I know how to go about
doing a regular table view with text data. Thank You.
You don't want to return an actual button from the table datasource.
The way to go about it is to set the dataCell of the column to an
NSButtonCell, and then return an NSNumber representing the value
the control should take for that column.
To wit:
//do this somewhere in the setup code, like awakeFromNib or something
[[[tableView
tableColumnWithIdentifier:@"ButtonColumnIdent"]setDataCell:buttonCellInstance]
;
The table column retains the buttonCell instance so you don't need
to hold onto it.
Then in the objectValueForTableColumn... method do something like this:
if([[tableColumn identifier]isEqualToString:@"ButtonColumnIdent"])
{
//return either:
return [NSNumber numberWithInt:0];
//or this:
return [NSNumber numberWithInt:1];
}
Responding to user clicks on the button is the same, but in
reverse...8-)
Brian
email@hidden
http://personalpages.tds.net/~brian_hill
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman