我试图将UILabel与在类中创建的IBOutlet链接起来。
我的应用程序崩溃与以下错误。
这是什么意思?
我该怎么解决呢?
***终止应用由于未捕获异常'NSUnknownKeyException',原因:'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键XXX。'
我试图将UILabel与在类中创建的IBOutlet链接起来。
我的应用程序崩溃与以下错误。
这是什么意思?
我该怎么解决呢?
***终止应用由于未捕获异常'NSUnknownKeyException',原因:'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键XXX。'
当前回答
我记得在过去也遇到过类似的问题,我通过改变一行来解决它:
_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殉死
其他回答
"这个类不符合键值编码" 我知道有点晚了,但我的答案是不同的,所以我认为它需要张贴,我推错了第二个控制器的方式,这里是样本
错误的推控制器方式
UIViewController* controller = [[UIViewController
alloc]initWithNibName:@"TempViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:true];
正确的方法
TempViewController* controller = [[TempViewController
alloc]initWithNibName:@"TempViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:true];
我没有找到如上的答案,所以它可能可以帮助一些有同样问题的人
您只需要指定IBOutlet一次,IBOutlet标签您的ivar是不必要的。 你在用你的UIViewController实例化你的NIB吗?在某些时候,你应该调用[SecondView initWithNibName:@"yourNibName" bundle:nil];
我已经经历过两次了。
解决方案是重新制作整个故事板,因为我从另一个故事板复制了它(因为它几乎是相同的)
你的视图控制器可能在xib中有错误的类。
我下载了你的项目。
你得到的错误是
'NSUnknownKeyException',原因:'[<UIViewController 0x3927310> setValue:forUndefinedKey:]:这个类不是键值编码兼容的键字符串。'
这是由主窗口中的第二个视图控制器引起的。xib有一个UIViewController类而不是SecondView。更改到正确的类可以解决这个问题。
顺便说一下,在Objective-C中使用"string"这样的名字是不好的做法。它会引起运行时命名冲突。即使是在一次性练习应用程序中也要避免使用它们。命名冲突很难追踪,你不想浪费时间。
这个错误的另一个可能的原因是:当从一个控制器复制和粘贴元素到另一个控制器时,Xcode以某种方式保留了原始控制器的链接,即使在编辑和重新链接这个元素到新的控制器之后。
造成这个错误的另一个可能原因是:
糟糕的出口。
您在.h文件中删除或重命名了一个出口名称。
在.xib或.storyboard文件的连接检查器中删除它。
还有一个可能的原因
(在我的情况下)扩展带有可绑定属性的UIView,并为这些可绑定属性设置值(即阴影,角半径等),然后从UIView扩展中删除这些属性(出于某种原因),但以下<userDefinedRuntimeAttributes>保留在xml (of foo.storyboard)中:
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
<point key="value" x="5" y="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
<real key="value" value="16"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
解决方案:右键单击foo。删除导致问题的</userDefinedRuntimeAttributes
我在故事板中得到这个错误。上面的解决方案似乎不是问题,所以我最终删除了视图控制器,并再次将它添加回来(当然,重新连接segue并重新分配类),这就修复了它。我不知道它到底是什么,但我在这个开始前不久重命名了关联的视图控制器类,所以可能有一些东西。