FROM : Bruce Truax
DATE : Sun Dec 12 14:36:50 2004
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_removed>> 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
>> --
DATE : Sun Dec 12 14:36:50 2004
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_removed>> 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
>> --
| Related mails | Author | Date |
|---|---|---|
| Bruce Truax | Dec 11, 02:57 | |
| Jonathan Jackel | Dec 12, 00:51 | |
| Bruce Truax | Dec 12, 14:36 | |
| Jonathan Jackel | Dec 12, 18:17 | |
| Bruce Truax | Dec 12, 19:03 | |
| Jonathan Jackel | Dec 12, 19:55 | |
| Bruce Truax | Dec 12, 20:12 | |
| Guy English | Dec 13, 19:41 |






Cocoa mail archive

