我正在創建登錄註冊頁面,但有錯誤。當我嘗試登錄時,userStoredEmailuser和userStoredPassword返回null。請幫助解決這個錯誤。NSUserDefaults.standardUserDefaults()。stringForKey(「useremail」)返回值爲空的值
登錄代碼:
let useremail=email.text;
let userpassword=password.text;
let userStoredEmail = NSUserDefaults.standardUserDefaults().stringForKey("useremail") //return null
let userStoredPassword = NSUserDefaults.standardUserDefaults().stringForKey("userpassword") //return null
// print(emails);
// print(userStoredEmail);
Registreration代碼:
let useremail=email.text;
let userpassword=password.text;
let userRePassword = RePassword.text;
//check for empty field
//store data
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject("useremail", forKey: useremail!)
defaults.setObject("userpassword", forKey: userpassword!)
defaults.synchronize()
let alert1 = UIAlertController(title: "Alert", message:"Registration is succesfully complete", preferredStyle:.Alert)
// add an action (button)
alert1.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(alert1, animated: true, completion: nil)
,你叫這個'讓userStoredEmail = NSUserDefaults.standardUserDefaults()。stringForKey(「useremail」)// return null' in viewdidload or else ' –
'key value for key property – karthikeyan
在IBAction onclick按鈕我稱這userstroedEmail @ anbu.karthik –