0

也许你们中的一些人知道如何将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 Ula

4

1 回答 1

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)
}
于 2017-10-24T09:42:42.080 回答