用户偏好问题的设置

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

 

    

    NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

    

    NSLog(@"%@",doc);

    

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    // NSLog(@"%@",doc);

    

    //保存数据

    [defaults setObject:@"zhangsan" forKey:@"account"];

    [defaults setObject:@"123" forKey:@"passwd"];

    

    [defaults setBool:YES forKey:@"autoLogin"];

    

    [defaults setBool:YES forKey:@"rememberPwd"];

    

    //调用同步方法,把数据保存到沙盒文件中

    [defaults synchronize];

    

    

    NSString *name = [defaults objectForKey:@"account"];

    NSString *password = [defaults objectForKey:@"passwd"];

   

    NSLog(@"%@, %@", name, password);

 }

posted on 2017-01-01 20:59  1018475062  阅读(130)  评论(0编辑  收藏  举报