Checkboxes in NSTableView
Checkboxes in NSTableView
- Subject: Checkboxes in NSTableView
- From: Mark T <email@hidden>
- Date: Mon, 13 Aug 2001 14:59:56 -0400
I'm having some problems with using checkboxes(NSSwitchButton) in one
of the columns of a table view. I've followed what directions I could
find on this list and some other places and have successfully gotten
the checkboxes to display. The problem is that they seem unable to
hold a value. I've even set the action for them to set their state to
on, but sometime before the next click, it resets to off. Here is (I
think) all the code pertaining to it:
//In controller.m
- (void)awakeFromNib
{
NSButtonCell *aCell = [[[NSButtonCell alloc] init] autorelease];
[theTable setDataSource:theDataSource];
[theTable setDelegate:self];
[aCell setControlSize: NSRegularControlSize];
[aCell setTitle:@""];
[aCell setButtonType:NSSwitchButton];
[aCell setShowsStateBy:NSContentsCellMask];
[aCell setEnabled:YES];
[aCell setTransparent:NO];
[aCell setState:YES];
[aCell setTarget:self];
[aCell setAction:@selector(checkboxChanged:)];
[[theTable tableColumnWithIdentifier:@""] setDataCell:aCell];
}
- (IBAction)checkboxChanged:(id)sender
{
NSCell * aCell = [[sender tableColumnWithIdentifier:@""]
dataCellForRow:[sender selectedRow]];
NSLog(@"State: %d", [aCell state]);
[aCell setNextState];
NSLog(@"State: %d", [aCell state]);
}
//in datasource.m
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSButton * aButton = [[NSButton alloc] init];
NSParameterAssert(rowIndex >= 0 && rowIndex < [self
numberOfRowsInTableView:aTableView]);
[aButton setTitle:@""];
[aButton setButtonType:NSSwitchButton];
[aButton setEnabled:YES];
[aButton setTransparent:NO];
[aButton setTarget:self];
[aButton setAction:@selector(checkboxChanged:)];
if([[aTableColumn identifier] isEqualTo:@""])
return aButton;
/* the rest of the code for other columns... */
}
Is this wrong? Is it missing vital parts? both?
Any help you be appreciated,
Mark T.
References: | |
| >Re: (From: "swc" <email@hidden>) |