问题
I am having some trouble with debugging a UIButton. There is an error I don't know how to fix. I almost certain it is within this code somewhere. Here is my code:
@IBAction func checkButton(sender: UIButton) {
if (flashButton.hidden == true){
flashButton.hidden == false
flashingImageView.hidden == true
}else if (flashButton.hidden == false)
{
flashButton.hidden == true
flashingImageView.hidden == false
}
if ( "\(randomImageGeneratorNumber)" == "\(currentCountLabel.text)"){
currentAmountCorrect + currentAmountCorrect + 1
amountCorrectLabel.text = "\(currentAmountCorrect)"
}else{
currentAmountIncorrect = currentAmountIncorrect + 1
amountIncorrectLabel.text = "\(currentAmountIncorrect)"
}
if (currentCountLabel.text == "0"){
let alert = UIAlertView()
alert.title = "Alert"
alert.message = "You must type in an answer in order to check it"
alert.addButtonWithTitle("Understood")
alert.show()
}
currentCount *= 0
currentCountLabel.text = "\(currentCount)"
}
The error in the debugger output says: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key CheckButton.'
I am not sure how to fix this. Any Suggestions?
Thanks in Advance.
回答1:
This can happen if you accidentally create an @IBOutlet
to your button, and then just delete the IBOutlet
from the code. In this situation, the Storyboard still tries to hook up the button to the @IBOutlet
property in your ViewController
, but it fails because the IBOutlet
in the code is gone. If this is indeed what you did, to fix it:
- Control-click on the button in the Storyboard.
From the list that pops up, scroll down to the Referencing Outlets section at the bottom.
There, if you see an outlet listed, click on the
x
next to theViewController
to delete this outlet.
来源:https://stackoverflow.com/questions/28781565/trouble-debugging-uibutton