【发布时间】:2013-12-20 11:57:27
【问题描述】:
我为存储用户名和密码的假冒用户创建了一个对象,然后将该对象放入字典中。现在我正在尝试使用 NSUserDefault 存储字典,但它不让我。我理解最好不要使用 NSUserDefault 来存储用户数据,但这只是我正在尝试学习的初学者。
/**interface file **/
#import "newUser.h"
@interface BWViewController : UIViewController
{
IBOutlet UITextField *userNameField;
IBOutlet UITextField *passwordField;
IBOutlet UILabel * loginStatus;
}
@property (nonatomic, copy) NSDictionary * aUser;
-(IBAction)signUpButton;
@end
/**implementation file**/
@interface BWViewController ()
@end
@implementation BWViewController
@synthesize aUser;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction) signUpButton
{
newUser * firstUser = [[newUser alloc] init];
firstUser.userName = userNameField.text;
firstUser.password = passwordField.text;
NSLog(@"%@", firstUser.userName); /**for testing**/
NSLog(@"%@", firstUser.password); /**for testing**/
aUser = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:firstUser, nil] forKeys:[NSArray arrayWithObjects:userNameField.text, nil]];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:aUser forKey:userNameField.text];
[defaults synchronize];
loginStatus.text = @"Thanks for signing up!";
}
【问题讨论】:
标签: objective-c