Re: Archiving NSTableViews
Re: Archiving NSTableViews
- Subject: Re: Archiving NSTableViews
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 21 Apr 2004 11:24:45 -0700
On Apr 21, 2004, at 9:57 AM, Glenn Zelniker wrote:
I have a problem with archiving and unarchiving NSTableViews. I've
already found a solution, but it's inelegant and was hoping there
would be a better way to do it.
Are you actually archiving the table view itself?
The way I figured to get around the problem is to unarchive the table
object to a "dummy" NSTableView in the loadDataRepresentation:ofType
method. Then in the windowControllerDidLoadNib method I go through the
columns of the dummy table and append them to the table that comes out
of the Nib file. And it works fine, I should add, but it seems
inelegant. I was wondering if there's any way to suppress the
extraction of the table from the Nib file and "drop" the proper table
into the correct place in the GUI. In other words, I like using IB to
put the table in the right place, put a NSBox around it, and configure
the table and I don't want to have to do that programmatically, but at
the same time the way I'm doing it now seems kludgy.
Any suggestions?
Rather than actually archiving the table view, archive the identifiers
(and if appropriate, titles -- see below) of the new columns. When the
document is reloaded, recreate the table columns:
For each newTitle and newIdentifier:
NSTableColumn tc = [[NSTableColumn alloc] initWithIdentifier:
newIdentifier];
// then set the title:
[[tc headerCell] setStringValue: newTitle];
// and add the column:
[tableView addTableColumn: tc];
[tc release];
What's not clear, though, is whether you have a fixed set of columns
from which the user may choose, or if the user is able to configure
their own columns. If the former, you may find it easier to configure
all the table columns in IB, and add and remove them directly as
necessary. You can store removed columns in a dictionary with their
identifier as the key. You would then simply store a list of the
identifiers of all the currently-visible columns.
mmalc
_______________________________________________
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.