dumb bindings/user defaults question
dumb bindings/user defaults question
- Subject: dumb bindings/user defaults question
- From: "Andrew R. Kinnie" <email@hidden>
- Date: Sun, 8 Apr 2007 15:06:14 -0400
Greetings:
I am working on a document based app, and I'm using the user defaults
bindings mechanism. I created a plist with the relevant key/value
combination (basically a string for a key and an int that corresponds
to the key). I loaded this as factory defaults, and created several
keys that can be reset by the user.
In my app I created a text field bound to one of these keys in the
user defaults. This works fine.
I decided it was better to put this on a separate preferences panel.
I created a panel in the MainMenu.nib and placed the text field bound
the same way on that panel (SharedUserDefaults -> values.myKey) The
panel is bound to the Preferences menu item (makeKeyAndOrderFront).
However, the initial values do not appear when the preference panel
is loaded. I can use my factory defaults button or my revert button
and this populates the field with values, and I can change them,
apply the changes, etc.
If I change the values, apply it, then reload it, the CHANGED values
appear, but still not the initial/factory ones.
Anyone have an idea what I might be missing? Here is my initialize
method (straight from the docs)
+ (void)initialize
{
[MyDocument setupDefaults];
}
+ (void)setupDefaults
{
NSString *userDefaultsValuesPath;
NSDictionary *userDefaultsValuesDict;
NSDictionary *initialValuesDict;
NSArray *resettableUserDefaultsKeys;
// load the default values for the user defaults
userDefaultsValuesPath=[[NSBundle mainBundle]
pathForResource:@"UserDefaults"
ofType:@"plist"];
userDefaultsValuesDict=[NSDictionary
dictionaryWithContentsOfFile:userDefaultsValuesPath];
// set them in the standard user defaults
[[NSUserDefaults standardUserDefaults]
registerDefaults:userDefaultsValuesDict];
resettableUserDefaultsKeys=[NSArray
arrayWithObjects:@"myKey1",@"myKey2",@"myKey3",nil];
initialValuesDict=[userDefaultsValuesDict
dictionaryWithValuesForKeys:resettableUserDefaultsKeys];
[[NSUserDefaultsController sharedUserDefaultsController]
setInitialValues:initialValuesDict];
}
Thanks.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden