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: Bruce Truax <email@hidden>
- Date: Sun, 12 Dec 2004 08:36:50 -0500
I have implemented these methods in my datasource object. When I have used
table views in the past I have always used bindings and I have bound each
column to the column of the table. In this case I cannot do that because
the array is created dynamically and I do not have advance knowledge of the
columns. It appears that I need to start with an empty table and then add
columns dynamically which I do as follows:
for (i=0;i<10;i++)
{
NSTableColumn *theColumn = [[NSTableColumn alloc] init];
[theColumn setIdentifier:[NSString stringWithFormat:@"i%",i]];
[displayArrayTable addTableColumn:theColumn];
[theColumn release];
}
I set the identifier of each column as a string which is the same as the
column number. This is also the key that I use in the dictionary
representing the objects in each row. (At your suggestion that table views
are really set up to deal with arrays of dictionaries.)
I then do the following:
[self setDisplayArray:[[DLDDisplayArray alloc]
initWithCArray:outputArray
withXDimension:xSize
withYDimensiont:ySize]];
[displayArray retain];
[displayArrayTable setDataSource:displayArray];
[displayArrayTable setNeedsDisplay:YES];
I end up with a table containing the correct number of columns (all with the
column header title "FIELD" but no data in the table. I think some of the
problem is related to my column identifiers but the documentation is unclear
as to how these should be specified. I appears that they should be the
strings representing the keys for each column but I am not sure.
Bruce
On 12/11/04 6:51 PM, "Jonathan Jackel" <email@hidden> eloquently
wrote:
> 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
>> --
_______________________________________________
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