ios - Issue in NSUserDefaults LoginView with UISwitch -
i'm unable store username , password in loginview
when enable rememberme
switch.
here code, kindly me!
- (void)viewdidload { if (rememberswitch.on == yes){ self.usernamefield.text = usernamefield.text; self.passwordfield.text = passwordfield.text ; }else{ nslog(@"switch off"); self.usernamefield.text = @""; self.passwordfield.text = @""; } } - (ibaction)remembermetouched:(id)sender { nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; if (rememberswitch.on == yes) { nsstring *userstring = usernamefield.text; [userdefaults setobject:userstring forkey:@"userstring"]; nsstring *passwordstring = passwordfield.text; [userdefaults setobject:passwordstring forkey:@"passwordstring"]; } [userdefaults setobject:(rememberswitch.on ? @"true" : @"false") forkey:@"isremember"]; [userdefaults synchronize]; }
you need load content nsuserdefault code should this:
if (rememberswitch.on == yes){ self.usernamefield.text = [userdefaults objectforkey:@"userstring"];; self.passwordfield.text = [userdefaults objectforkey:@"passwordstring"];; }
Comments
Post a Comment