@IBOutlet weak var studyID: UITextField!
@IBOutlet weak var userID: UITextField!
let username: String = self.studyID.text!
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(username, forKey: "username")
下次打开此应用时,如何存储用户名和显示内容?
答案 0 :(得分:1)
将其放在String
viewDidAppear()
确保成功保存。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
username = NSUserDefaults.standardUserDefaults().objectForKey("username") as! String
print(username)
}