In article <K5mdnV53a5dRANPVnZ2dnUVZ_hCdnZ2d@[EMAIL PROTECTED]
>,
Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> After going through the docs I can find on the NSTableView class, I'm
> still left with no clue how to work with the darn things. They look like
> they'd be the ideal way to present the data in the project I'm messing
> with to the user (I gather my data and stuff it into an NSMutableArray
> holding "items" - Each individual item is an object with all of the
> pertinent data for that item - Description, ID number, price, etc) but I
> can't figure out how to even get started using the class.
>
> The NSTableView reference is fine - as far as it goes. Ditto the
> "conceptual" that goes with it. But neither helps me at all in actually
> *USING* them!
>
> I need something that shows me what's involved in actually making it
> work.
It's actually fairly simple. You have to identify to the table view an
object that will be the table's data source - you can do that in IB or
in code. You also want to assign (in IB) useful strings to the
'identifier' value for each column. If your data objects were
dictionaries or are KVC-compliant, the names of the keys you use would
be excellent choices.
The data source object needs to implement two methods (3 if your table
accepts input).
- (int)numberOfRowsInTableView:(NSTableView*)aTableView
{
return [myArray count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
id theIdentifier = [aTableColumn identifier];
id theEntry = [myArray objectAtIndex:rowIndex];
id theResult = nil;
/*
** Some code that uses theIdentifier to extract the proper value
** from theEntry and assign it to theResult. If your entries are
** dictionaries or KVC-compliant, for instance:
** theResult = [theEntry objectForKey:theIdentifier];
*/
return theResult;
}
If any table columns are editable:
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
id theIdentifier = [aTableColumn identifier];
id theEntry = [myArray objectAtIndex:rowIndex];
/*
** Code that modifies theEntry appropriately, such as:
** [theEntry setObject:anObject forKey:theIdentifier
*/
}
Those are all that are required. There are some additional methods you
can implement if you want to handle sorting and/or dragging. You can
also assign an object as the table's delegate; that gets to handle other
messages that do things like re****t state changes in the table as a
whole.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
- Harry Potter and the Odor of the Phoenix


|