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

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

这是什么意思?

我该怎么解决呢?

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


当前回答

这个错误是另一回事!

这是我如何解决它。我使用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.

欢呼,

其他回答

我的方法和杰拉德·格伦迪类似。在使用XIB创建自定义UITableViewCell时,我错误地将自定义类名称应用到文件的所有者而不是UITableViewCell。将类应用到画布上的UITableViewCell并将IBOutlet属性连接到它上解决了这个问题。

这种情况只发生在我在设备(iPhone)上调试时。iOS模拟器运行正常。用Xcode做一个“Product->Clean”似乎解决了这个问题,但我不知道为什么。

另一个棘手的例子:

在IB中,将ViewController添加到storyboard,删除它的视图,并将自定义类设置为“MyViewController”,以便从MyViewController.xib实例化视图

将Storyboard ID指定为相同的“MyViewController”会导致异常。

将故事板ID更改为其他名称可以解决该问题。

NSUnknownKeyException error

'NSUnknownKeyException', reason: this class is not key value coding-compliant for the key

我得到这个错误时。xib文件(例如。TableViewCell.xib)具有与单元格类相同的名称(例如。TableViewCell.swift)

正确的做法是:

TableViewCell.swift -> View.swift <-> View.xib

正如@FranticRock提到的,这个帖子真的是一个史诗般的传奇故事。

对我来说

出水口连接正确 “Inherit From Target”有一个正确的值,这意味着模块被正确添加

在我的案例中导致崩溃的原因是标识检查器下的用户定义运行时属性

我有一个视图,以某种方式有三个属性borderColor, borderWidth和cornerRadius

从视图中删除这些属性就解决了这个问题。