为什么单击按钮时会出现 NSUnknownKeyException?

Why do I get NSUnknownKeyException when I click on a button?

app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button_1.'

class ViewController: UIViewController {

@IBAction func button1_pressed(sender: AnyObject) {
    NSLog("hello");
}

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.
}

}

您似乎没有定义出口(再)。情节提要仍然认为有一个 @IBOutlet weak var button_1: UIButton? 但你显然已经删除了它。

检查故事板或 xib(无论您使用哪个)。此错误最可能的来源是某些内容与代码中不存在的操作或出口有联系。