User Defaults Bindings confusion
User Defaults Bindings confusion
- Subject: User Defaults Bindings confusion
- From: "Andrew R. Kinnie" <email@hidden>
- Date: Thu, 13 Apr 2006 11:25:51 -0400
Greetings,
I am re-writing an app using Core Data and bindings, and as part of
this, I am trying to use the user defaults bindings mechanism for the
first time.
I have created the default values based on Aaron Hillegass's book by
creating external strings to use as keys, which I set at the default
values. (i.e. in the app delegate's .h I declare them below import
and above interface:
extern NSString *myKey;
Then I set the value in the .m file:
NSString * myKey = @"myKeyString";
Then I use the initialize method:
+ (void)initialize
{
// setup default values (per BNR)
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
[defaultValues setObject:[NSNumber numberWithInt:1]
forKey: myKeyString];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
NSLog(@"registered defaults: %@", defaultValues);
}
This all seems to work. However, I then try to bind this value to a
preferences panel in my MainMenu.nib file in IB. I have a text box
with a number formatter, and want the user to be able to type in a
number for the key. I set the text box's Value binding to bind value
to the Shared User Defaults Controller, controller key set to values,
and the model key path of myKey.
My panel has an apply button which is set to the "save" action of the
user defaults controller.
I have a button on the main interface window which has a button
matrix set to an action in the app delegate which has as its first line:
NSLog(@"number from user defaults: %@", [[NSUserDefaults
standardUserDefaults] valueForKey:myKey]);
Unfortunately, when I run the app, and change the value, it does
appear to be properly saved (the new value appears next time the app
is run), but when I press the button on the main window the NSLog
call returns the original values not the new values.
This leads me to believe I am missing something. (otherwise binding
defaults seems to be quite useless, and this seems quite unlikely).
Can someone point me in the right direction?
Thanks.
Andrew
_______________________________________________
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