gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:24:08 24 4
gpt4 key购买 nike

我正在尝试将 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/3088059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com