• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How To: translate column identifier in table view to message selector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: How To: translate column identifier in table view to message selector
      • From: Bill Cheeseman <email@hidden>
    • Re: How To: translate column identifier in table view to message selector
      • From: Robert Cerny <email@hidden>
  • Prev by Date: movie
  • Next by Date: Re: How To: translate column identifier in table view to message selector
  • Previous by thread: Re: movie
  • Next by thread: Re: How To: translate column identifier in table view to message selector
  • Index(es):
    • Date
    • Thread