Re: Displaying an NSArray of NSArray's in a Table view
Re: Displaying an NSArray of NSArray's in a Table view
- Subject: Re: Displaying an NSArray of NSArray's in a Table view
- From: Jonathan Jackel <email@hidden>
- Date: Sat, 11 Dec 2004 18:51:55 -0500
Table views are really set up to deal with arrays of dictionaries, not
arrays of arrays. Also, to understand table views you need to
understand table columns as well. I would spend some time with the
NSTableView and NSTableColumn docs (NSArray and NSMutableArray docs,
too).
I imagine that there is some clever way of making this work with
bindings, but I don't know it. I would use a data source and five
lines of code.
In the table datasource, implement this (written in Mail):
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [rows count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
int columnIndex = [[aTableView tableColumns]
indexOfObject:aTableColumn];
return [[rows objectAtIndex:rowIndex]
objectAtIndex:columnIndex];
}
- (void)tableView:(NSTableView *)aTableView
setObjectValue:anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
int columnIndex = [[aTableView tableColumns]
indexOfObject:aTableColumn];
[[rows objectAtIndex:rowIndex] replaceObjectAtIndex:columnIndex
withObject:anObject];
}
Jonathan
On Dec 10, 2004, at 8:57 PM, Bruce Truax wrote:
As some of you have seen from an earlier post, I have taken a two
dimensional C array of floats and created an NSMutableArray (rows) of
NSMutableArrays (columns) of NSNumbers which I created from the C
array of
floats. It seems that this should be easy to display in a table view
but it
is not obvious how to do this. Binding the content array of the table
view
to the NSMutableArray does not cause the display, neither does setting
the
data source.
Suggestions are appreciated.
Bruce
--
____________________________________________________________
Bruce E. Truax email: email@hidden
Optical Engineering Consultant
Diffraction Limited Design LLC
388 Wedgewood Road voice: 860-276-0450
Southington, CT 06489 fax: 860-620-9026
http://www.dld-llc.com
_____________________________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden