A problem of NSUserdefaults
A problem of NSUserdefaults
- Subject: A problem of NSUserdefaults
- From: "Bus Mini" <email@hidden>
- Date: Fri, 14 Jul 2006 00:48:30 +0800
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:
This email sent to email@hidden