Re: NSTableView and check boxes (for the hundredth time)
Re: NSTableView and check boxes (for the hundredth time)
- Subject: Re: NSTableView and check boxes (for the hundredth time)
- From: Vladimir Pilipyuk <email@hidden>
- Date: Thu, 3 Oct 2002 17:03:53 +0400
Hi Jan,
Your code should display check boxes in the @"status" column, it seems
OK. Are you sure, you set column identifier in IB correctly?
On Thursday, October 3, 2002, at 04:50 am, Jan Van Tol wrote:
I know this has been discussed MANY times before on this list, but
I've read the archives relating to this, and it still won't work.
When I run this, I just get a column of zeros instead of checkboxes.
What am I doing wrong? Here is the code I'm trying to use:
NSButtonCell *protoCell;
protoCell=[[NSButtonCell alloc] init];
[protoCell setButtonType:NSSwitchButton];
[protoCell setImagePosition:NSImageOnly];
[protoCell setTitle:@""];
[checkboxColumn setDataCell:protoCell];
The protoCell should be released here. It is now retained by
checkboxColumn.
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
if ([identifier isEqualToString:@"status"]) {
return [NSNumber numberWithBool: NO];
}
return nil;
}
The table view sends setState: messages with NSOnState and NSOffState
to button cells according to NSNumber value received from data source.
You do not have to implement delegate method willDisplayCell if only
these two states are required.
The only thing to be aware is that NSTableView corrupts its data cells
of type NSButtonCell when NSTableView is deallocated. Not the case with
NSImageCell which might be reused if retained. The NSButtonCell will
crash program inside its setState: method if reused this way in another
table view after deallocation of the first table. Obvious workaround is
to setDataCell:nil before releasing table view, but I would recommend
to allocate one NSButtonCell per column.
One more suggestion is to send setControlSize:NSSmallControlSize to
NSButtonCells of types NSRadioButton and NSSwitchButton if you want
them to fit into default row height.
Sincerely,
Vladimir
_______________________________________________
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.