Re: Newbie Question: NSTableView.DataSource
Re: Newbie Question: NSTableView.DataSource
- Subject: Re: Newbie Question: NSTableView.DataSource
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 10 May 2001 19:29:57 -0700
On Thursday, May 10, 2001, at 05:56 PM, William Jamieson wrote:
Hello All!!!
I am building a Cocoa Java application that requires the use and
manipulation of table data. I have created a NSTableView with four
columns
(the easy part!!!).
The documentation available tells me (as I understand it) that I need to
create an object to connect to the NSTableView as its DataSource (hence
NSTableView.DataSource) and that this object requires 3 methods (2 if
the
table data is not editable). These are:
NumberOfRowsInTableView()
TableViewObjectValueForLocation()
TableViewSetObjectValueForLocation() -- Required for editing data
What I don't understand (in my infinite lack of wisdom) is what kind of
object I can/should connect to the NSTableView as its DataSource. To
this
effect I have 5 main questions:
1. Should the DataSource object be a SubClass of NSMutableArray which
is an
array of arrays (an array of rows)?
It doesn't matter what the class of the data source is, just that it
responds to all the methods listed.
2. Do I need to instantiate the object attached as the NSTableView's
DataSource (whatever kind of object it is)?
An object can't do anything if it doesn't exist ;-)
YOu can either instantiate it in IB, or create it programmatically and
attach it to the table view with setDataSource:
3. Can the object connected as the NSTableView's DataSource be my main
controller class for the application?
Yep. (That might be a bit of a sub-optimal design choice, but still,
the only *requirement* for the datasource is that it must respond to
the messages that a table view will send to its datasource.
4. What is the best way to implement the 3 methods mentioned above?
That's a pretty open-ended question.
5. Should the dataSource object be the same as the delegate object for
the
NSTableView? What are the problems/benefits in doing this?
It can be, and a lot of people do it this way. For my part, I tend to
keep delegates and data sources separate, since one is concerned with
UI, and the other is all about the data.
-jcr
Support your right to protest a criminal nut-cult.
http://freehenson.tripod.com/