Re: How To: translate column identifier in table view to message selector
Re: How To: translate column identifier in table view to message selector
- Subject: Re: How To: translate column identifier in table view to message selector
- From: Robert Cerny <email@hidden>
- Date: Wed, 26 Nov 2003 13:42:22 +0100
Hi,
you can use NSSelectorFromString. Simply add your selectors as strings
into dict.
SEL NSSelectorFromString(NSString *aSelectorName)
HTH
Robert
On 26.11.2003, at 13:28, Frank wrote:
>
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.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.