iOS UI 连接代码

iOS UI connection to the code

每次我 运行 这个代码都会给出 Terminating app due to uncaught exception 'NSUnknownKeyException',setValue:forUndefinedKey:]: this class is not key value coding.' 我所做的只是将 button 连接到 label

class ViewController: UIViewController {

    @IBOutlet weak var lable: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func button(_ sender: Any) {
        lable.text="done"
    }

}

错误将参考class AppDelegate: UIResponder, UIApplicationDelegate

转到您的故事板,select您的 ViewController 并转到此部分

检查您这里没有任何无效的 Outlet。如果您连接一个插座,然后通过代码更改变量的名称,xcode 仍会尝试找到前一个并会崩溃。