# I need help with NSTableView.



## lelereb (Apr 16, 2001)

I'm new in Java and Cocoa programming.

I don't understand how implements a NSTableView and his dataSource.

Someone has a simple example of it to send me?
	<emanuelerebuttini@mac.com>

Tanks a lot.


----------



## iconara (Jun 16, 2002)

I realize that this was posted more than a year ago, but if someone (like myself) would stumble upon the post, it would be nice with an answer:

ok. you need a class that implements these methods:


```
- (int)numberOfRowsInTableView:(NSTableView *)tableView;

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)col row:(int)row;
```

then you register that class as the tables data source:


```
// assume that table is a NSTableView or NSOutlineView
// assume that dataSrc is an instance of your class

[table setDataSource:dataSrc];
```


example of implementation of the methods above:


```
// assume that we have an instance variable called "array" which is a NSArray

- (int)numberOfRowsInTableView:(NSTableView *)tableView { return [array count]; }

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)col row:(int)row {
 
 	return [array objectAtIndex:row];
      
}
```

You could also make a category for the NSArray class that implements the two methods above and use an array directly as data source (there is an example of this in the Cocoa documentation, wish that I remembered where)


Theo


----------

