Re: NSTableView & different columns
Re: NSTableView & different columns
- Subject: Re: NSTableView & different columns
- From: Dave Hersey <email@hidden>
- Date: Sat, 02 Jul 2005 17:27:30 -0400
>> Nevertheless, how can I return multiple different behaviour for
>> multiple different columns?
>> If the identifiers of the columns are, e.g. "Numbers" and "Buttons",
>> how can I in a single method return different values for column
>> behaving?
>
> By using "if - else" to branch depending on the value of aTableColumn.
>
> (For some reason, that obvious answer is not intuitive. I remember
> scratching my own head for quite a few minutes over that one and then
> jumping up and slapping my forehead!)
Or, you could use a key-value approach, which avoids the need for the if
statement. If you do it like this, then you just need methods in your data
objects that can respond to the column identifiers.
So, if the identifiers are "number" and "button", you'd have number,
setNumber, button, and setButton methods in the data object and include the
code below in your table's data source. (Here, I was storing the table
objects using an array.)
- Dave
- (id) tableView: (NSTableView *) tableView
objectValueForTableColumn: (NSTableColumn *) tableColumn
row: (int) rowIndex
{
id theObject = nil, theValue = nil;
NSString *identifier = [tableColumn identifier];
NSArray *dataStorage = [[tableView dataSource] dataStorage];
if (dataStorage)
{
theObject = [dataStorage objectAtIndex: rowIndex];
theValue = [theObject valueForKey: identifier];
}
return theValue;
}
- (void) tableView: (NSTableView *) tableView
setObjectValue: (id) anObject
forTableColumn: (NSTableColumn *) tableColumn
row: (int) rowIndex
{
id theObject;
NSString *identifier = [tableColumn identifier];
NSArray *dataStorage = [[tableView dataSource] dataStorage];
if (dataStorage)
{
theObject = [dataStorage objectAtIndex: rowIndex];
[theObject takeValue: anObject forKey: identifier];
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden