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

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

这是什么意思?

我该怎么解决呢?

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


当前回答

看看其他的答案,似乎有很多事情可以导致这个错误。这里还有一个。

如果你

拥有自定义视图 添加了@IBInspectable属性 然后又删除了

那么您也可能会得到类似的错误

在[您的自定义]上设置(xxx)用户定义的被检查属性失败 视图)……:这个类不是键值编码兼容的 [xxx]。

解决方案是删除旧属性。

打开类的Identity检查器,在User Defined Runtime Attributes下选择属性名,然后按减号按钮(-)。

其他回答

我记得在过去也遇到过类似的问题,我通过改变一行来解决它:

_vicMain = [[UIViewController alloc] initWithNibName:@"vicMainScreen" bundle:nil];

成:

#include "vicLogin_iPad.h"       // This is the H file of the class holding the code for
                                 // processing all the IBOUtlets for the Login screen
.
.
.

_vicMain = [[vicLogin_iPad alloc] initWithNibName:@"vicMainScreen" bundle:nil];

注意,我最初声明UIViewController初始化我的_vicMain,在顶部使用弹出窗口后,我意识到两者都使用相同的UIViewController。

By:

1)包括你的类(子视图),以及相同的模块,正在做上面的_vicMain(这是一个视图控制器对象/变量),即它是“vicLogin_iPad.h”在我的情况下,和:

2)使用你的自定义构造函数来声明对象(例如,而不是“xxx = [UIViewController alloc]…”,使用“xxx = [vicLogin_iPad alloc]…””。

问题解决了。

我希望这能有所帮助,因为这是一个痛苦的定位与缺乏细节的错误消息…

问候 Heider殉死

这个错误是另一回事!

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

欢呼,

我得到了同样的错误,当我手动加载一个视图从一个笔尖。结果是我忘记设置视图的所有者。

例如,如果你以以下方式加载一个视图,

 let view = Bundle.main.loadNibNamed("MyNibFileName",
                                 owner: nil,
                                 options: nil)?.first as! UIView

然后添加一个IBOutlet, IBOutlet不能被引用,应用程序会因为上面的错误而崩溃。

修复:为视图分配一个所有者。

 let view = Bundle.main.loadNibNamed("MyNibFileName",
                                 owner: self,
                                 options: nil)?.first as! UIView

我已经经历过两次了。

解决方案是重新制作整个故事板,因为我从另一个故事板复制了它(因为它几乎是相同的)

有时swift文件没有从目标中添加或删除,请转到目标——>构建设置——>编译源——>查看是否缺少任何所需的swift类文件。 在我的情况下,应用程序崩溃,由于swift源文件不存在编译。