Re: Preferences
Re: Preferences
- Subject: Re: Preferences
- From: Scott Anguish <email@hidden>
- Date: Wed, 7 Apr 2004 20:30:37 -0400
On Apr 7, 2004, at 7:49 PM, Scott Anguish wrote:
- add a method that sets up the initalValues for the shared
controller, this must be called before ANY nibs that use the
sharedUserDefaultsController are loaded.
- registers the default values with NSUserDefaults using
registerDefaults:
- this might be the same dictionary used with the initialValues:,
(I can explain the situations where it isn't, but usually it should
be)
Let me clarify this... since the code I wrote didn't do the
registerDefaults: (and it should have). I'd really appreciate feedback
on this as well, since it's a tad confusing...
the NSUserDefaultsController offers an initialValues dictionary, and
there is some confusion as it somewhat collides with the NSUserDefaults
method registerDefaults:
This is a bit confusing, and there seems to be a bit of contention
about how to work with this. This will be in the next update of the
bindings doc though...
So, in general
when you use NSUserDefaultsController the search order for the value
of a key is
- the value corresponding to the key in the -values of the
NSUserDefaultsController
- the value corresponding to the key in the -userDefaults for that
controller
- this in turn checks the registration Domain (registerDefaults:)
- the initialValues dictionary.
But, if you use NSUserDefaults, you don't get any access to the
userdefaultscontroller, or the initialValues
So... here's my suggestion..
register your defaults using registerDefaults: on NSUserDefaults
register any default values that can be reset by the user clicking the
"Reset to Factory Defaults" button in the preferences in the
initialValues dictionary of the sharedUserDefaultsController
Here's where it gets a bit trickier still.
In the implementation of your preferences panel you'll likely want to
use the controller values exclusively. If you need to update them
manually (if there is something that you don't have handling for in
Bindings, perhaps a folder setting button.. where you'd display the
bound value inthe text field, but you'd set it by clicking on a button
and then need to insert the value yourself) do a setValue:thevalue
forkey: on the -values of the shareduserDefaultsController. likewise,
if you need to display something in the prefs, use the value from the
values in the sharedUserDefaultsZController.. this way you get to use
the reverttoInitialValues, ,and the ability to apply the values later
(turning off appliesImmediately)
BUT.. elsewhere in your application, unless you're binding a value
directly to a user interface item... use the NSUserDefaults methods
directly.
_______________________________________________
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.