Re: NSTableView as an Outlet
Re: NSTableView as an Outlet
- Subject: Re: NSTableView as an Outlet
- From: Michael Rogers <email@hidden>
- Date: Tue, 5 Jun 2001 22:16:12 -0500
On Tuesday, June 5, 2001, at 07:16 PM, email@hidden wrote:
I saw an example of NSTableView where the NSTableView is the
dataSource, but how can I use it as an outlet.
Lets say I have a project with an NSTableView object that is an outlet
under the name "tableView"
How do I change the number of rows? Can I do it in a statement like
[tableView numberOfRowsInTableView:10] or do I need to put it into a
function? If so how and what do the parts of that mean?
An NSTableView doesn't contain its own data -- rather it uses a data
source, which is another object entirely.
So, using NSTableView is a two step process.
1. Create the data source. To do so, create a class, any class at all,
that will contain the data you want to display in the table. It might
be in an NSArray within that class, for example. The important thing is
that class *must* implement two methods:
-(int)numberOfRowsInTableView;
-(id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)column row:(int)row;
The first method returns the number of rows in the NSTableView. So, if
you wrote:
-(int)numberOfRowsInTableView {
return 10;
}
then your NSTableView would display exactly 10 rows.
The second method returns the object that you wish to display in the
specified column and row. Most likely you'll store this in an array.
2. In IB, draw a connection from your NSTableView to an instance of the
class you defined in step 1, and click on dataSource. (Actually, you'll
need to double click on the NSTableView because it's really nested
within something else. When the NSTableView turns gray, you'll see
dataSource appear in the Show Info palette (in the Connections portion).
Although it has seen its share of criticism in this list, IMHO the
Learning Cocoa coverage of NSTableViews is excellent, and you should
read that for more information.
HTH,
Michael
------------------------------
Dr. Michael P. Rogers
Mathematics & Computer Science, Millikin University
email@hidden
http://math.millikin.edu/mprogers
217-424-6327(W) 309-828-8655 (H) 309-825-6454(C)