也许有人知道如何在clearButton.setTitle
中放置UserDefaults
参数,然后将其覆盖func viewDidLoad() {
我尝试在viewDidLoad
准备密钥之前尝试的参数,但我认为defaults.set
不正确
let defaults = UserDefaults.standard
let clearB = "clearB"
clearButton.setTitle("Clear", for: .normal )
defaults.set(clearButton.setTitle, forKey: clearB).
感谢您的帮助 BR 乌拉
答案 0 :(得分:0)
let clearB = "clearB"
clearButton.setTitle("Clear", for: .normal )
UserDefaults.standard.set(clearButton.titleLabel!.text, forKey: clearB)
提取:
if let title = UserDefaults.standard.string(forKey: clearB) {
clearButton.setTitle(title, for: .normal)
}