• 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: Creating a checkbox
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a checkbox


  • Subject: Re: Creating a checkbox
  • From: Eric Peyton <email@hidden>
  • Date: Fri, 12 Apr 2002 07:48:59 -0500

You can do it either way. The sample that I took the code from wasn't always a checkbox in that column. Occasionally it was another kind of button so it made far more sense to set it to what it needed to be on the outline view check ...

Eric

On Friday, April 12, 2002, at 04:27 AM, Stiphane Sudre wrote:

On Thursday, April 11, 2002, at 07:58 PM, Eric Peyton wrote:

On Thursday, April 11, 2002, at 12:35 PM, Mike O'Connor wrote:

I have a table where one column contains checkboxes and another contains
sliders. So I have to set this up programmatically.

How do I create a checkbox? Looks like I start with an NSButton, but how do
I set it up? IB has a "checkbox" button type, but I can't really tell what
it's doing.


Set the cell for the column to be a button

[checkColumn setDataCell:[[NSButtonCell alloc] init]];

Then, when the cell is being displayed using ...

- (void)outlineView:(NSOutlineView *)ov willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
if (tableColumn == fileCheckColumn) {

[cell setButtonType:NSSwitchButton];
[cell setControlSize:NSSmallControlSize];
[cell setAllowsMixedState:YES]; (if you want to allow 3 state checkboxes)
[cell setState:NO];

[cell setAction:@selector(your_action:)];
}
}

Is this really the recommended way of doing it?

I would have thought this part :

[cell setButtonType:NSSwitchButton];
[cell setControlSize:NSSmallControlSize];
[cell setAllowsMixedState:YES]; (if you want to allow 3 state checkboxes)

would be in the [checkColumn setDataCell:[[NSButtonCell alloc] init]] part.

This would give for a Table (not an outlineView):

in - (void) awakeFromNib

NSTableColumn *tColumn;
id tPrototypeCell;

tPrototypeCell = [[[NSButtonCell alloc] initTextCell: @""] autorelease];
[tPrototypeCell setEditable: YES]; // Not sure this one is necessary
[tPrototypeCell setButtonType:NSSwitchButton];
[tPrototypeCell setImagePosition:NSImageOnly]; // This line is useful if you want to center the checkbox
[tPrototypeCell setControlSize:NSSmallControlSize];

tColumn=[IBarray_ tableColumnWithIdentifier:@"Status"];
[tColumn setDataCell:tPrototypeCell];

and to display the value of the cell:

- (id) tableView:(NSTableView *) inTableView objectValueForTableColumn:(NSTableColumn *) inColumn row: (int) inRow
{
if ([[inColumn identifier] isEqualToString:@"Status"])
{
return [NSNumber numberWithBool: NO]; /* Put your BOOL value here */
}

return nil;
}

and to get set values:

- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)inColumn row:(int)inRow
{
if ([[inColumn identifier] isEqualToString:@"Status"])
{
if ([object boolValue] == YES)
{

}
else
{

}
}
}
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Re: Creating a checkbox (From: Stéphane Sudre <email@hidden>)

  • Prev by Date: Re: Java Cocoa - App doesnt work outside of PB
  • Next by Date: NSImage -isValid not always right?
  • Previous by thread: Re: Creating a checkbox
  • Next by thread: Re: Creating a checkbox
  • Index(es):
    • Date
    • Thread