hunterp
hunterp

Reputation: 15986

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

}

Upvotes: 0

Views: 69

Answers (2)

Uttam Sinha
Uttam Sinha

Reputation: 722

Check storyboard or xib (whichever you're using). The most likely source of this error is that something has a connection to an action or outlet that doesn't exist in the code.

Upvotes: 0

Glorfindel
Glorfindel

Reputation: 22641

It seems that you have no outlet defined (anymore). The storyboard still thinks there is an @IBOutlet weak var button_1: UIButton? but you have deleted it apparently.

Upvotes: 1

Related Questions