• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Checkboxes in NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Checkboxes in NSTableView
      • From: Scott Herz <email@hidden>
    • Re: Checkboxes in NSTableView
      • From: Sarat Kongara <email@hidden>
References: 
 >Re: (From: "swc" <email@hidden>)

  • Prev by Date: Re: questions
  • Next by Date: Downloading html page
  • Previous by thread: Re: EOF Advocacy
  • Next by thread: Re: Checkboxes in NSTableView
  • Index(es):
    • Date
    • Thread