首先要在
AppDelegate.h里面定义
NSDictionary *userDefaults;
@property (nonatomic, retain) NSDictionary *userDefaults;
在AppDelegate.m里 @synthesize userDefaults;
//本地存储密码
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setObject:user forKey:@"user"];
[userDefault setObject:pwd forKey:@"pwd"];
AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];
myDelegate.userDefaults = userDefault;
//取用户名密码
AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];
NSString *user = [myDelegate.userDefaults valueForKey:@"user"];
NSString *pwd = [myDelegate.userDefaults valueForKey:@"pwd"];
好了,大功告成。