【问题标题】:Trouble Debugging UIButton调试 UIButton 时遇到问题
【发布时间】:2015-02-28 12:13:50
【问题描述】:

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

@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)"

}

调试器输出中的错误说: '[setValue:forUndefinedKey:]: 这个类对于键 CheckButton 不兼容键值编码。'

我不确定如何解决这个问题。有什么建议吗?

提前致谢。

【问题讨论】:

  • 检查您的按钮是否在 Interface Builder 中正确连接。
  • 连接正确

标签: debugging swift uibutton ibaction


【解决方案1】:

如果您不小心为按钮创建了@IBOutlet,然后从代码中删除了IBOutlet,就会发生这种情况。在这种情况下,Storyboard 仍然尝试将按钮连接到您的ViewController 中的@IBOutlet 属性,但它失败了,因为代码中的IBOutlet 消失了。如果这确实是您所做的,请修复它:

  1. 控制-点击故事板中的按钮。

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

  3. 在那里,如果您看到列出的出口,请单击 ViewController 旁边的 x 以删除此出口。

【讨论】:

  • 我是重新连接按钮还是在删除插座后保持原样?
  • 在弹出窗口中,Touch Up Inside 是否像我的图片中那样连接到您的按钮?如果没有,那么可以,只需控制从按钮到 checkButton 例程的拖动即可。
  • 连接方式和你的图片一样。
  • 如果您去掉Referencing Outlets 部分下的CheckButton 插座,您的按钮应该可以正常工作而不会崩溃。
  • 我运行调试器时仍然出现同样的错误。
猜你喜欢
  • 1970-01-01
  • 2014-07-09
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 2011-10-29
  • 2017-09-04
  • 1970-01-01
相关资源
最近更新 更多