【问题标题】:Why do I get NSUnknownKeyException when I click on a button?为什么单击按钮时会出现 NSUnknownKeyException?
【发布时间】:2015-04-07 16:48:30
【问题描述】:

应用程序由于未捕获的异常“NSUnknownKeyException”,原因: '[setValue:forUndefinedKey:]: 此类与键 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.
}

}

【问题讨论】:

标签: ios swift


【解决方案1】:

您似乎(不再)没有定义出口。故事板仍然认为有一个@IBOutlet weak var button_1: UIButton?,但您显然已将其删除。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2011-01-28
      • 2014-12-22
      • 2019-09-22
      相关资源
      最近更新 更多