Re: NSTableView question
Re: NSTableView question
- Subject: Re: NSTableView question
- From: Jeremy Dronfield <email@hidden>
- Date: Tue, 15 Feb 2005 11:22:22 +0000
On 15 Feb 2005, at 9:11 am, Peter Karlsson wrote:
Dear list!
I have a tableview with one column. In that column I have thousands of
names. I need a way to give these names id's.
For example if I click on a name, I want that id. And if I click on
another
name, I want that id and so on. But this must also work after I have
sorted
the table in alphabetical order, or moved the names around. The names
can
be duplicates so I can't use the names as id's.
I'm thinking of using 2 columns in my table, one for the names and a
second
(hidden) one for the id's, but is this really the best way to go?
The first thing you need to understand is that a table view's data does
not belong to the the table view; it's precisely what it says it is -
just a view. Therefore, there isn't necessarily a one-to-one
relationship between your data model and the layout of your table view.
Your data source manages the data and passes to the table view that
portion/slice/representation of the data you want to show to the user.
In this case, your data could be an array of dictionaries, with each
dictionary containing a value for "name" and a value for "id". Your
table has just one column, and in the data source method
-tableView:objectValueForTableColumn:row:, you return the value for
"name":
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theObject = [myDataArray objectAtIndex:rowIndex];
id theValue = [theObject objectForKey:@"name"];
return theValue;
}
The table view (and therefore the user) never needs to know that a
value for "id" even exists. To get an "id" value for a selected row,
all you need to do is
[[myDataArray objectAtIndex:[myTableView selectedRow]]
objectForKey:@"id"]
Regards,
-Jeremy
===================================
SkoobySoft, home of viJournal and Skooby Renamer
email: email@hidden or visit:
http://freespace.virgin.net/jeremy.dronfield/skoobysoft.html
===================================
_______________________________________________
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