• 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
Re: TableColumn dataCell actions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TableColumn dataCell actions


  • Subject: Re: TableColumn dataCell actions
  • From: mmalcolm crawford <email@hidden>
  • Date: Sun, 10 Nov 2002 01:29:10 -0800

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

  • Follow-Ups:
    • Re: TableColumn dataCell actions
      • From: Angela Brett <email@hidden>
References: 
 >TableColumn dataCell actions (From: Angela Brett <email@hidden>)

  • Prev by Date: Re: Calling a unix command from Cocoa ? (Marco Binder)
  • Next by Date: Re: Move a file to the Trash
  • Previous by thread: TableColumn dataCell actions
  • Next by thread: Re: TableColumn dataCell actions
  • Index(es):
    • Date
    • Thread