NSUserDefaults 本地小量数据存储

时间:2022-11-14 05:35:46

  

1.在注册界面点击事件  把数据存进去

   NSUserDefaults *user = [NSUserDefaults standardUserDefaults];

    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:_ac1.text,@"name",_pw1.text,@"password", nil];
    [user setObject:dic forKey:@"user"];

    [self.navigationController popViewControllerAnimated:YES];



2.在登录界面 点击事件里 把数据取出来


  NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"user"];
    if ([_oneV.aa.text isEqualToString:[dic objectForKey:@"name"]] && [_oneV.bb.text isEqualToString:[dic objectForKey:@"passwaord"]]) {


        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@" 登录成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }else{
    
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"登录失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定 ", nil];
        
        [alert show];
    
    }