Initialising NSTableColumn ??? Continued from : Setting NSPopUpButtonCell Value from NSTable
Initialising NSTableColumn ??? Continued from : Setting NSPopUpButtonCell Value from NSTable
- Subject: Initialising NSTableColumn ??? Continued from : Setting NSPopUpButtonCell Value from NSTable
- From: "Alexander F. Hartner" <email@hidden>
- Date: Sun, 4 Jul 2004 13:47:25 +0200
I ended up subclassing NSTableColumn and implemented dataCellForRow, At
first I created a new instance of a NSPopupButtonCell for each
invocation, but this very bad. I want to maintain a collections of
cells and return a reference to the same instance on each invocation. I
implemented the init method, but is never is called.
- (id)init
{
NSLog(@"Initialised ContactFieldColumn");
return self;
}
- (id)initWithIdentifier:(id)identifier;
{
NSLog(@"Initialised ContactFieldColumn");
[super initWithIdentifier:identifier];
int index=0;
popups = [NSMutableArray arrayWithCapacity:20];
for (index=0; index<20; index++)
{
NSPopUpButtonCell *cell=[[NSPopUpButtonCell alloc] init];
[cell setBordered:NO];
NSMutableArray * titles = [NSMutableArray arrayWithCapacity:4];
[titles addObject:@"Mr"];
[titles addObject:@"Ms"];
[titles addObject:@"Mrs"];
[titles addObject:[[NSNumber numberWithInt:index]stringValue]];
[cell addItemsWithTitles:titles];
[popups addObject:cell];
}
return self;
}
- (id)dataCellForRow:(int)row
{
NSLog(@"Reloading cells for row");
return [popups objectAtIndex:row];
}
What constructor / init method must I provide to perform this kind of
initialisation.
thanks
Alex
On 01 Jul 2004, at 3:56, Daniel Todd Currie wrote:
>
Look into NSTableColumn's -dataCell and -dataCellForRow: methods.
>
>
-- DTC
>
>
>
On 2004 Jun 30, at 12:45, Alexander F. Hartner wrote:
>
>
> 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.
_______________________________________________
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.