这是什么意思? “NSUnknownKeyException”,原因:...该类不是关键字编码符合键X“ [英] What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"
问题描述
我想尝试将 UILabel
与在我的课程中创建的 IBOutlet
相关联。
I'm trying to link a UILabel
with an IBOutlet
created in my class.
我的应用程序崩溃,出现以下错误。这是什么意思?
My application is crashing with the following error. What does this mean? How can I fix it?
***由于未捕获异常NSUnknownKeyException终止应用程序,原因:'[< UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:此类不是键值编码兼容的键XXX。'
*** 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中可能有错误的类。
我下载了您的项目。
Your view controller may have the wrong class in your xib.
I downloaded your project.
您得到的错误是
'NSUnknownKeyException' [< UIViewController 0x3927310> setValue:forUndefinedKey:]:这个类不是键值编码符合键字符串。'
'NSUnknownKeyException', reason: '[<UIViewController 0x3927310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key string.'
它是由
MainWindow.xib
中的 类的
。更改为正确的类可解决问题。 > UIViewController
而不是 SecondView
It is caused by the Second
view controller in MainWindow.xib
having a class of UIViewController
instead of SecondView
. Changing to the correct class resolves the problem.
顺便说一下,在Objective-C中使用string这样的名字是不好的做法。它邀请运行时命名冲突。避免他们即使在一次关闭实践应用程序。命名冲突可能很难跟踪,你不想浪费时间。
By the way, it is bad practice to have names like "string" in Objective-C. It invites a runtime naming collision. Avoid them even in once off practice apps. Naming collisions can be very hard to track down and you don't want to waste the time.
此错误的另一个可能原因:当复制&粘贴元素从一个控制器到另一个,Xcode以某种方式保持该链接到原始控制器,即使在编辑&将此元素重新链接到新控制器中。
Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller.
这篇关于这是什么意思? “NSUnknownKeyException”,原因:...该类不是关键字编码符合键X“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!