Re: A problem of NSUserdefaults
Re: A problem of NSUserdefaults
- Subject: Re: A problem of NSUserdefaults
- From: Yorh <email@hidden>
- Date: Thu, 13 Jul 2006 19:00:46 +0200
Do you quit the appliocation using xcode button or by command q?
Because the prefs are saved only when the application receive the
termination message....
bye
Yorh
On 13/lug/06, at 18:48, Bus Mini wrote:
Hi all,
I have run into a problem when using NSUserdefaults. That is, I did
change
the value of NSUserDefaults ,but the next time I run my
application, the
preferences is the old one. Followed is my code, could any one help
me find
my problem? Thanks very much.
@interface MyObject : NSObject
{
IBOutlet id myOutlet1;
IBOutlet id myOutlet2;
IBOutlet id myOutlet3;
IBOutlet id myOutlet4;
NSUserDefaults * prefs;
}
- (IBAction)save:(id)sender;
@end
#import "MyObject.h"
@implementation MyObject
- (IBAction)save:(id)sender
{
[prefs setObject:[myOutlet1 stringValue] forKey:@"FavBook"];
[prefs setObject:[myOutlet1 stringValue] forKey:@"FavCity"];
[prefs setObject:[myOutlet1 stringValue] forKey:@"FavColor"];
[prefs setObject:[myOutlet1 stringValue] forKey:@"FavFood"];
}
- (id)init
{
[super init];
NSMutableDictionary * defaultPrefs = [NSMutableDictionary
dictionary];
[defaultPrefs setObject:@"Learning Cocoa"
forKey:@"FavBook"];
[defaultPrefs setObject:@"San Francisco"
forKey:@"FavCity"];
[defaultPrefs setObject:@"Red"
forKey:@"FavColor"];
[defaultPrefs setObject:@"Mexican" forKey:@"FavFood"];
prefs = [[NSUserDefaults standardUserDefaults]
retain];
[prefs
registerDefaults:defaultPrefs];
return self;
}
- (void)dealloc
{
[prefs release];
[super dealloc];
}
- (void)awakeFromNib
{
[myOutlet1 setStringValue:[prefs stringForKey:@"FavBook"]];
[myOutlet2 setStringValue:[prefs stringForKey:@"FavCity"]];
[myOutlet3 setStringValue:[prefs stringForKey:@"FavColor"]];
[myOutlet4 setStringValue:[prefs stringForKey:@"FavFood"]];
}
@end
--
Yours sincerely
Mini Bus.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40metagraphics.it
This email sent to email@hidden
_______________________________________________
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