我试图将UILabel与在类中创建的IBOutlet链接起来。

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

这是什么意思?

我该怎么解决呢?

***终止应用由于未捕获异常'NSUnknownKeyException',原因:'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键XXX。'


当前回答

还有其他问题,你可以在其他答案中看到。 我为自己创建这个错误的方式是,我从头开始一个项目,首先删除故事板的初始场景,然后将另一个项目的场景粘贴到我的故事板中。

那样做没有问题。你只需要在你的故事板中添加一个入口点,也就是检查你喜欢的任何视图控制器上的初始视图控制器。否则它将是一个灰色的场景,并向您抛出一个错误。

其他回答

导致这种情况的另一个原因是,您声明该属性实现为@dynamic,但类无法在父类中找到它。

如果您试图观察一个不存在的值,请注意。

这发生在我身上只是因为我正在观察一个文本字段的“文本”属性,而我应该观察的是“文本”属性。

我尝试了这篇文章中的每一个选项。唯一为我解决这个问题的是改变我的自定义视图xib文件的名称。

我的自定义视图和xib有相同的名称。重命名xib修复了它。

我在一个有两个目标(有自己的MainWindow XIB)的项目中遇到了类似的问题。对我来说,导致这个错误的根本问题是UIViewController类没有包含在第二个项目的资源列表中。例如,界面构建器允许我在主窗口中指定它。Xib,但在运行时系统无法定位类。

例如,cmd-点击有问题的UIViewController类,并仔细检查它是否包含在“Targets”选项卡中。

这个错误是另一回事!

这是我如何解决它。我使用xcode版本6.1.1和使用swift。每次我的应用程序尝试执行segue跳转到下一个屏幕时,我都得到这个错误。这是我所做的。

Checked that the button was connected to the right action.(This wasn't the problem, but still good to check) Check that the button does not have any additional actions or outlets that you may have created by mistake. (This wasn't the problem, but still good to check) Check the logs and make sure that all the buttons in the NEXT SCREEN have the correct actions, and if there are any segues, make sure that they have a unique identifier. (This was the problem) One of the segues did not have a unique identifier One of the buttons had an action and two outlets that I created by mistake. Delete any additional outlets and make sure that you the segues to the next screen have unique identifiers.

欢呼,