FROM : Andrew R. Kinnie
DATE : Sun Apr 08 21:06:14 2007
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.
DATE : Sun Apr 08 21:06:14 2007
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.
| Related mails | Author | Date |
|---|---|---|
| Andrew R. Kinnie | Apr 8, 21:06 | |
| Matt Neuburg | Apr 9, 18:22 | |
| Andrew Kinnie | Apr 9, 19:19 |






Cocoa mail archive

