• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: still wrestling with dynamic columns and column auto-resizing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: still wrestling with dynamic columns and column auto-resizing


  • Subject: Re: still wrestling with dynamic columns and column auto-resizing
  • From: HORUS Technologies <email@hidden>
  • Date: Fri, 5 May 2006 07:49:57 +0200


Le 5 mai 06 à 04:53, Matt Neuburg <email@hidden> a écrit :

Hello Matt,

In my NSTableView, the user can ask for many columns to come and go. That's
what I mean by "dynamic columns". It's like in the Finder where a pref says
what columns appear in list view, or like in iTunes.


Well, this is turning out to be tremendously difficult.

It all stems from the fact that I want to remember the user's column choices
and column widths after the app quits. When the app starts up, I restore the
appropriate columns dynamically.

I remember doing something like that last summer, but I don't remember encountering any of the problems you mention here.
I stored all the characteristics of the columns in a dictionary and restored them like this:


- (void)addTableColumnForKey:(NSString *)key
{
NSSortDescriptor* sortDesc;

NSTableColumn *aColumn = [[NSTableColumn alloc] initWithIdentifier:key];
[aColumn autorelease]; // The column will be retained by the NSTable

NSDictionary *columnParams = [columnsDictionary objectForKey:key];
if (columnParams) {
[aColumn setResizingMask: [(NSNumber*)[columnParams valueForKey:@"resizingMask"] intValue]];
[[aColumn headerCell] setStringValue: [columnParams valueForKey:@"header"]];
// Add the formatter for the column
// If some columns don't need one or need a different one, you need handle the special cases
// This can be done easily by looking at a key in the dictionary describing the column for example
NSNumberFormatter *nbrFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[nbrFormatter setFormat:@"0;0;-0"];
if ([columnParams objectForKey:@"minValue"] != nil) [nbrFormatter setMinimum:[columnParams valueForKey:@"minValue"]];
if ([columnParams objectForKey:@"maxValue"] != nil) [nbrFormatter setMaximum:[columnParams valueForKey:@"maxValue"]];
[[aColumn dataCell] setFormatter:nbrFormatter];
// Add the sort descriptor
sortDesc=[[[NSSortDescriptor alloc] initWithKey:key ascending:YES selector:@selector(compare:)] autorelease];
[aColumn setSortDescriptorPrototype:sortDesc];
// Establish bindings
// Note that the width, min width and max width are restored here
[aColumn bind:@"value" toObject:listArrayController withKeyPath: [columnParams valueForKey:@"binding"] options:nil];
[aColumn bind:@"width" toObject:self withKeyPath:[NSString stringWithFormat:@"columnsDictionary.%@.width", key] options:nil];
[aColumn bind:@"minWidth" toObject:self withKeyPath:[NSString stringWithFormat:@"columnsDictionary.%@.minWidth", key] options:nil];
[aColumn bind:@"maxWidth" toObject:self withKeyPath:[NSString stringWithFormat:@"columnsDictionary.%@.maxWidth", key] options:nil];

// Finally, add the column to the table
[mainList addTableColumn:aColumn];
}
}


You have to add the columns in the right order or shift them but I don't think it will be a problem.

I hope this can help you.

Olivier



_______________________________________________
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


  • Prev by Date: Opening and Closing a file in Invisible mode
  • Next by Date: Re: (simple?) CoreData question :-)
  • Previous by thread: still wrestling with dynamic columns and column auto-resizing
  • Next by thread: Re: still wrestling with dynamic columns and column auto-resizing
  • Index(es):
    • Date
    • Thread