• 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: "Manually" saving NSTableView info
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Manually" saving NSTableView info


  • Subject: Re: "Manually" saving NSTableView info
  • From: Chris Giordano <email@hidden>
  • Date: Thu, 27 May 2004 10:30:16 -0400

Gabe,

On May 26, 2004, at 4:16 PM, Gabriele de Simone wrote:

I have a simple app based on NSDocument. My document window contains an NSTableView, and I would like to save window location/size and NSTableView configuration along with the document data. Saving window info is easy since NSWindow provides convenient methods to retrieve and set the frame info from a string, but nothing comparable exists for NSTableView... am I missing something?


This is what I'm doing to save and restore table columns. I write the column information (order and size) into the document when I'm saving, and restore it in my NSDocument subclass's windowControllerDidLoadNib: method. I restore the width and the order of the saved columns by enumerating my saved columns, setting the width of the column to the saved value, and then putting them in the order of those saved. I leave any columns not mentioned in the document (i.e., not saved) in the table after those saved. You may or may not want to do that, depending on your goals.

Hope this helps.

chris

-----

Background:

NSTableView * registerTable; // the table whose columns are being saved

Save:

NSArray * columns = [registerTable tableColumns];
NSEnumerator * e = [columns objectEnumerator];
NSTableColumn * item;
NSDictionary * dict;
NSMutableArray * res = [NSMutableArray arrayWithCapacity:[columns count]];
NSArray * keys = [NSArray arrayWithObjects:@"identifier", @"width", nil];
while (item = [e nextObject])
{
dict = [item dictionaryWithValuesForKeys:keys];
[res addObject:dict];
}
// the array "res" is then archived in my document

Load:

NSArray * columnAttributes; // the array unarchived from my document corresponding to "res" above

NSTableColumn * col;
NSEnumerator * e = [columnAttributes objectEnumerator];
NSDictionary * d;
NSString * ident;
float width;
int idx;
int i = 0;
while (d = [e nextObject])
{
ident = [d valueForKey:@"identifier"];
width = [[d valueForKey:@"width"] floatValue];
if (ident)
{
col = [registerTable tableColumnWithIdentifier:ident];
idx = [registerTable columnWithIdentifier:ident];
if (col && (idx != -1))
{
if (width >= [col minWidth] && width <= [col maxWidth])
{
[col setWidth:width];
}
[registerTable moveColumn:idx toColumn:i];
++i;
}
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >"Manually" saving NSTableView info (From: Gabriele de Simone <email@hidden>)

  • Prev by Date: Re: How far with accessors?
  • Next by Date: Re: Flattening Mac resource files?
  • Previous by thread: "Manually" saving NSTableView info
  • Next by thread: NSTextView baseline for line of text
  • Index(es):
    • Date
    • Thread