Re: Setting NSPopUpButtonCell Value from NSTable
Re: Setting NSPopUpButtonCell Value from NSTable
- Subject: Re: Setting NSPopUpButtonCell Value from NSTable
- From: Mike Ferris <email@hidden>
- Date: Sat, 3 Jul 2004 11:53:38 -0700
To use a popup in a table you need to be aware of a couple things:
- The popup's contents should be configured directly into the
dataCell of the column. The list of contents is NOT the objectValue of
your row/column.
- The objectValue of your row/column is going to be the index of
the selected item in the popup (wrapped in an NSNumber).
So, if you fill the dataCell with the items "Mr", "Ms", and "Mrs" (in
IB or at nib load time) then you'll want to make your
objectValue/setObjectValue data source methods deal in [NSNumber
numberWithInt:0] for "Mr", [NSNumber numberWithInt:1] for "Ms", and so
on.
If you need different rows to have different values in the popup or
even different kinds of cells (like PropertyListEditor's Value column
which uses text fields in some rows, and popups in others), look into
subclassing NSTableColumn and overriding -dataCellForRow:. A common
technique is to write a subclass of NSTableColumn that delegates
-dataCellForRow: to the containing table's delegate or datasource
(defining a delegate message like -tableView:dataCellForRow:column:)...
This way you can offload the custom contents to the
delegate/datasource and use the custom table column class whereever you
need per-row control over the dataCell...
Mike
Begin forwarded message:
From: "Alexander F. Hartner" <email@hidden>
Date: June 30, 2004 12:45:45 PM PDT
To: Cocoa-Dev <email@hidden>
Subject: Setting NSPopUpButtonCell Value from NSTable
I have configured a columnn containing NSPopUpButtons inside and
NSTable. I created a datasource and associated it my my table view. In
my DataSource I have added the following code:
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSMutableArray * titles = [NSMutableArray arrayWithCapacity:3];
[titles addObject:@"Mr"];
[titles addObject:@"Ms"];
[titles addObject:@"Mrs"];
[titles addObject:[[NSNumber numberWithInt:rowIndex]stringValue]];
NSLog([aTableColumn identifier]);
if ([[aTableColumn identifier] isEqualToString:@"Labels"])
{
return titles;
}
return titles;
}
For the default type of cell returning a String is fine, but how can I
set individual values for each row using a NSPopUpButtonCell. Returning
a NSString array does not work. Is it possible to use this mechanism at
all. I understand that the instance of the cell class is shared for all
cells in the same column and that the value is provided from the
datasource, but what value do I need to return for a NSPopUpButtonCell.
If this is not the right way of doing it, do i need to subclass
NSTableColumn and implement the dataCellForRow method ?This seems quite
a bit of effort for just setting the values ?
Thanks
Alex
_______________________________________________
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.