Re: Guidance for Cocoa's steep learning curve
Re: Guidance for Cocoa's steep learning curve
- Subject: Re: Guidance for Cocoa's steep learning curve
- From: Jens Alfke <email@hidden>
- Date: Thu, 15 May 2008 19:07:18 -0700
On 15 May '08, at 6:33 PM, Joseph Ayers wrote:
What is absolutely
baffling is dealing with NSTableView. The documentation absolutely
sucks. How does one map table rows and columns
on NSMutableArrays and NSMutableDictionaries. How does one map the
Rows and Columns of a "dataSource"
on a NSTable view?
I take it you read the table view programming guide and it didn't help?
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/TableView/Tasks/UsingTableDataSource.html
Basic table display is simple. As that page says:
Your data source object can store records in any way you choose, as
long as it is able to identify those records by integer index. It
must also implement methods to provide the following information:
* How many records are in the data source (numberOfRowsInTableView
method)
* What is the value of a specific record
(tableView:objectValueForTableColumn:row: method)
Lets say you're storing your data as an NSArray of NSDictionaries,
with each dictionary's keys matching the identifiers of the table
columns. Then all you have to do is:
- (int) numberOfRowsInTableView: (NSTableView*)table {
return [_rowArray count];
}
- (id) tableView: (NSTableView*)table objectValueForTableColumn:
(NSTableColumn*)column row: (int)row {
NSString *identifier = [tableColumn identifier];
return [[_rowArray objectAtIndex: row] objectForKey: identifier];
}
What about records and fields. Imagine growing up on Excel and then
dealing with NSTableView.
How did this Cocoa NSTableView architecture evolve. Where is the
history?
Excel is an application, not an API. All applications present friendly
interfaces to complex functionality behind the scenes. Welcome to the
complex functionality :) I'm sure Excel's internal classes or data
structures are at least as involved as NSTableView.
The key thing is that any generic table view has to support huge
numbers of rows, and arbitrary ways of storing the data. So the view
itself can't store the data for you. Instead it has to ask your code
to fetch each piece of data it needs to display. That's exactly what
those two methods I showed above do.
This isn't an unusual design. Java's Swing table component works the
same way, as did the ones in the old MacApp and PowerPlant frameworks.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden