故障调试UIButton [英] Trouble Debugging UIButton

查看:47
本文介绍了故障调试UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调试UIButton时遇到了一些麻烦.我不知道如何解决错误.我几乎可以肯定它在这段代码中的某个地方.这是我的代码:

  @IBAction func checkButton(sender:UIButton){如果(flashButton.hidden == true){flashButton.hidden ==否flashingImageView.hidden == true}否则,如果(flashButton.hidden == false){flashButton.hidden ==真flashingImageView.hidden ==否}if("\(randomImageGeneratorNumber)" =="\(currentCountLabel.text)"){currentAmountCorrect + currentAmountCorrect + 1amountCorrectLabel.text ="\(currentAmountCorrect)"}别的{currentAmountIncorrect = currentAmountIncorrect + 1amountIncorrectLabel.text ="\(currentAmountIncorrect)"}如果(currentCountLabel.text =="0"){让警报= UIAlertView()alert.title =警报"alert.message =您必须输入答案才能检查它"alert.addButtonWithTitle(了解了")alert.show()}currentCount * = 0currentCountLabel.text ="\(currentCount)" 

}

调试器输出中的错误显示:'[setValue:forUndefinedKey:]:此类与键CheckButton的键值编码不兼容.'

我不确定如何解决此问题.有什么建议吗?

预先感谢.

解决方案

如果您不小心在按钮上创建了 @IBOutlet ,然后删除了 IBOutlet 从代码中.在这种情况下,情节提要板仍尝试将按钮连接到 ViewController 中的 @IBOutlet 属性,但是失败,因为其中的 IBOutlet 代码不见了.如果确实如此,请对其进行修复:

  1. 控件-单击情节提要中的按钮.

  2. 从弹出的列表中,向下滚动到底部的 Referencing Outlets 部分.

  3. 在此处,如果看到列出的插座,请单击 ViewController 旁边的 x 删除此插座.

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.

解决方案

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:

  1. Control-click on the button in the Storyboard.

  2. From the list that pops up, scroll down to the Referencing Outlets section at the bottom.

  3. There, if you see an outlet listed, click on the x next to the ViewController to delete this outlet.

这篇关于故障调试UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆