ios - 为什么我在 setValue :forUndefinedKey:? 中得到 NSUnknownKeyException

标签 ios xcode swift

<分区>

我正在制作一个小型 iOS 应用程序,用于跟踪我在工作中打卡的时间。我对 Swift 和 Xcode 非常陌生,所以这对我来说是一个挑战。详细信息:我使用的是Xcode 7,目标开发是8.3。我相信我丢失了一些小东西,例如类文件。 应用程序在启动时崩溃。

错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ButtonIn.'

代码:

import UIKit

class ViewController: UIViewController {

    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.



    }
    @IBOutlet weak var Lb1: UILabel!

    @IBAction func ButtonIn(sender: AnyObject) {
        self.Lb1.text = "Clocked In!"
    }

    @IBAction func ButtonOut(sender: AnyObject) {
        self.Lb1.text = "Clocked Out!"
    }
}

enter image description here

enter image description here

enter image description here

最佳答案

这通常发生在绑定(bind)导出改变时。请按照以下步骤操作:

  • 转到有此问题的类(class)的 .xib 文件或 Storyboard场景。
  • 选择“文件所有者”
  • 在右侧面板上选择“显示连接检查器”
  • 如果您发现 ButtonIn 连接上有任何感叹号,请重新绑定(bind)它。

希望这对您有所帮助。

enter image description here

关于ios - 为什么我在 setValue :forUndefinedKey:? 中得到 NSUnknownKeyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32700193/

上一篇:ios - 如何向 GET 请求添加 header 字段和参数?

下一篇:ios - NSNumberFormatter、numberFromString 及其行为

相关文章:

iphone - 使用字符串对象的内容填充数组

ios - AudioKit Playground (错误 : 'Module compiled with Swift 3.1 cannot be imported in Swift 3.0.2' )

ios - 如何创建自定义 TextCell 和 TextRow,其中包含 UITextField 的子类?

ios - 在 ios 中使用查询字符串创建 NSURLRequest

ios - 用于解析的最快iOS数据格式

iphone - 如何访问 UINavigationController 中以前的 View 元素

c++ - 如果 stat 语句不起作用

ios - Swift:如何以编程方式在 View 末尾设置按钮

ios - Appstore - 如何使用新的 Xcode 项目更新应用程序

ios - 找到保留周期的最佳方法?