Re: resetting a table to defaults [repost]
Re: resetting a table to defaults [repost]
- Subject: Re: resetting a table to defaults [repost]
- From: "Louis C. Sacha" <email@hidden>
- Date: Thu, 2 Dec 2004 02:10:28 -0800
Hello...
Part of the problem is that there aren't really any saved "default"
settings for an NSTableView instance. The table only knows what it's
current settings are, and it knows how to look up whatever settings
are stored in the preferences by the autosave. So, when you want to
get rid of the autosaved settings (which are generally the same as
the current settings) there isn't anything to default back to.
When you quit and restart the app, the nib is reloaded and the
settings that were the "current settings" as archived in the nib are
used. There's no simple method call that can reset an existing
NSTableView instance to those saved settings from the nib.
Some random ideas regarding how you might implement this functionality:
1) Just hard code the "default" order and size of the columns
somewhere and write code to rearrange them whenever you want to reset.
2) Delete the entries for the autosaved layout in the user
preferences. Then load a second copy of the nib that contains the
tableView and replace the current tableView with the newly loaded
instance from the nib. This might be relatively easy if the setup is
extremely simple and there are only a few connections to update
(table's datasource and delgate, and a controller's outlet to the
table), but rapidly becomes more complicated as the number of other
objects that interact with the table increases, and may very well
become impossible to do cleanly if bindings are involved.
3) Delete the entries for the autosaved layout in the user
preferences. Load a second copy of the nib containing the tableView
and use it to look up the original order and width of the columns and
then manually rearrange the existing table. When you're done, discard
the second copy of the table.
4) Hard code the "default" settings (as they appear in the autosaved
user preferences) for the table somewhere and use registerDefaults:
to register them with NSUserDefaults in the
applicationWillFinishLaunching: method of the app's NSApplication
delegate. Then when you want to reset the layout, delete the entries
for the autosaved layout in the user preferences, and send the table
setAutosaveTableColumns:FALSE and then setAutosaveTableColumns:TRUE.
The table should update itself to the default settings you registered
with NSUserDefaults.
All of these have various pros and cons. Implementing code that
rearranges the table to a specific layout should be fairly
straightforward, but you still need to get the "default" layout from
somewhere.
If you choose to hard code information about the table layout
somewhere, the drawback is that the information needs to be updated
seperately (and for each different table layout) and you won't be
able to easily adjust the column layout for the tableView in
InterfaceBuilder anymore. Saving the hardcoded info for the default
layout in a seperate plist in the application's resources will help
to make your code cleaner, but can still be difficult to update. If
you use the registered app defaults it's possible (although unlikely)
that the format/keys of the preferences that store the autosaved
table layout will be changed in a way that breaks things or that
causes the saved settings to be ignored.
If you load an extra copy of the nib and replace the table or use it
to look up the default settings, you will need to be careful with the
way you load the second copy of the nib to ensure you don't
accidentally overwrite any unrelated existing outlets/connections and
make sure that all the related outlets/connections are updated
properly if necessary (seperating the tableView into it's own nib
eliminates some of these problems, but also makes the intial design
and wake-up code more complex).
Hope that helps,
Louis
I didn't receive an answer of any kind the first time I posted this
so I'll ask again. Does anyone have an idea about this?
I have a table with columns which the user can resize, reorder, etc.
I want to be able to reset them to the factory defaults. I assume
this is done by deleting the prefs for the table, which is what I'm
doing.
However, I've been unable to force the table to redraw itself to
show the defaults. The only way that works is quitting and
restarting the app.
I've tried these calls to force the change to take place but they don't work:
[ledger reloadData];
[ledger setNeedsDisplay:TRUE];
What have I missed?
_______________________________________________
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