Re: Dot View + creating custom NSTable
Re: Dot View + creating custom NSTable
- Subject: Re: Dot View + creating custom NSTable
- From: Ondra Cada <email@hidden>
- Date: Mon, 17 Sep 2001 16:15:22 +0200
Alex,
>
>>>>> Alex Reynolds (AR) wrote at Mon, 17 Sep 2001 09:38:13 -0400:
AR> -- how can one create a custom NSTable that generates itself from custom
AR> data that is not known beforehand?
...
AR> I went through the NSTable example in chapter 9. If you don't know the
AR> structure of the table beforehand, how can you create a valid nib file
AR> based on custom data, i.e. how do you handle an unknown number of
AR> columns, attributes, autosizing, etc.?
You can't do in in NIB, the NIB contents is static. In NIB you use a table
with one (or none, if you know how to do that) column and with some
reasonable default attributes. The other you then set programmatically, like
(this is actual code of one of my apps, somewhat gutted not to be too long):
// prepare the table
[table removeTableColumn:[[table tableColumns] objectAtIndex:0]]; // seems
there MUST be a column in the NIB :(((
for (en=[... objectEnumerator];dd=[en nextObject];) { // dd is a
NSDictionary with attributes
NSTableColumn *col=[[[NSTableColumn alloc] initWithIdentifier:[dd
objectForKey:MDTC_ID]] autorelease];
NSTextAlignment alignment=NSNaturalTextAlignment;
NSString *fmt=[dd objectForKey:MDTC_FORMAT];
[[col headerCell] setStringValue:[dd objectForKey:MDTC_NAME]];
if (fmt) [[col dataCell] setFormatter:[[[NSDateFormatter alloc]
initWithDateFormat:fmt allowNaturalLanguage:NO] autorelease]];
if ((o=[dd objectForKey:MDTC_ALIGNMENT])!=nil)
alignment=[o hasPrefix:@"l"]?NSLeftTextAlignment:[o
hasPrefix:@"c"]?NSCenterTextAlignment:NSRightTextAlignment;
[[col dataCell] setAlignment:alignment];
if ((o=[dd objectForKey:MDTC_WIDTH])!=nil) {
float min,curr,max;
BOOL fixed;
...
[col setMinWidth:min];
[col setMaxWidth:max];
[col setWidth:curr];
[col setResizable:!fixed];
}
[table addTableColumn:col];
}
[table setAutosaveName:[NSString stringWithFormat:@"DataTable--%@--%@v%@",...]];
[table setAutosaveTableColumns:YES];
AR> The documentation is not
AR> clear on how this would be accomplished.
I guess it is quite clear -- I've used it to accomplish that many times;
more often the code written just using the docs worked at the first try than
not.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc