ios - Xcode - 如何修复 'NSUnknownKeyException',原因 : … this class is not key value coding-compliant for the key X"error?

标签 ios macos cocoa cocoa-touch interface-builder

我正在尝试将 UILabel 与我类(class)中创建的 IBOutlet 相链接。

我的应用程序因以下错误而崩溃。

这是什么意思?

我该如何解决?

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.'

最佳答案

您的 xib 可能连接有问题。

这个错误我遇到过很多次了。虽然 TechZen 的回答在这种情况下是绝对正确的,但另一个常见原因是当您在 .h/.m 中更改 IBOutlet 属性的名称时,您已经连接到 nib 中的文件所有者.

从你的 Nib :

  1. 在 IB 中选择对象并转到“连接检查器”。
  2. 在“Referencing Outlets”下,确保您的对象没有仍然连接到旧属性名称...如果是,单击小“x”删除引用并再次构建。

    enter image description here

另一个常见原因,如果您使用的是 Storyboard,您的 UIButton 可能有多个分配(解决方案与 nib 几乎相同):

  1. 打开 Storyboard并右键单击 UIButton
  2. 您会看到这个按钮有多个分配/引用。 删除带有小“x”的“Main...”灰色窗口之一:

    example 2

关于ios - Xcode - 如何修复 'NSUnknownKeyException',原因 : … this class is not key value coding-compliant for the key X"error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36392479/

相关文章:

ios - 来自 Firebase 服务器的 Facebook API 请求

iphone - 如何找出 UITextField 中的当前插入符位置?

ios - NSOperationOperationQueue cancelAllOperations 方法不会停止操作

cocoa - 如何使我的 NSScroller 子类具有不同的宽度?

ios - 如何自动给图片添加二维码

ios - Swift 2.0 子类化 UIViewController 的子类并调用便利初始化器

c# - 使用 .NET Core 在 Mac OSX 上进行 Office (Excel) COM 互操作?

java - mac 上的 Android Studio : cant find System compiler

python - 为什么 `source` 在 .bash_profile 中与 virtualenvwrapper 一起使用?

objective-c - 根据维基百科,为什么 "call super"被视为反模式?