How To: translate column identifier in table view to message selector
How To: translate column identifier in table view to message selector
- Subject: How To: translate column identifier in table view to message selector
- From: Frank <email@hidden>
- Date: Wed, 26 Nov 2003 13:28:03 +0100
Hello,
I am working on a small app which uses a NSTableView. In the datasource
I would like to map the Column identifier (string type) to a message
selector in a fast way. Running through multiple if statements with
string comparisons doesn't seem very efficient. So I tried to look at
the alternative of creating a dictionary with selectors as values and
strings as keys. Unfortunately this doesn't work as the dictionary
doesn't accept selectors as values, only objects. I could wrap the
selector in an object, but that would require one extra method call for
every single cell.
The way I wanted to work is something like:
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn*)aTableColumn
row:(int)rowIndex
{
id target;
NSString *column;
SEL command;
if((rowIndex >= 0) && (rowIndex <= [list count])) {
target = [list objectAtIndex: rowIndex];
column = [aTableColumn identifier];
command = [columnTranslator valueForKey:column]; // Does not work,
Dictionary cannot store SEL
return [target performSelector: command];
}
}
What is the best way to do this?
Regards,
Frank
_______________________________________________
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.