ios 此类不符合键视图的键值编码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10152872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:51:04  来源:igfitidea点击:

this class is not key value coding-compliant for the key view

iphoneobjective-ciosxcode

提问by hugoboss

i′m very new to xcode... a made an app (simple calculator) work′s pretty good (on simulator and device). When i set the main interface in the summaryoptions from Target, i get the following error when starting the simulator:

我对 xcode 很陌生……一个制作的应用程序(简单的计算器)工作得很好(在模拟器和设备上)。当我在Target摘要选项中设置主界面时,启动模拟器时出现以下错误:

2012-04-14 12:17:27.123 CalcTest[27550:f803] *Terminating app due to uncaught exception 'NSUnknownKeyException',

reason: '[<UIApplication 0x6a14650> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calculatorScreen.'

*First throw call stack: (0x12db022 0x18f8cd6 0x12daee1 0xcc2022 0xc33f6b 0xc33edb 0xc4ed50 0x53671a 0x12dcdea 0x12467f1 0x53526e 0x536eb7 0x313ce1 0x313ff8 0x31317f 0x322183 0x322c38 0x316634 0x27fcef5 0x12af195 0x1213ff2 0x12128da 0x1211d84 0x1211c9b 0x312c65 0x314626 0x1bad 0x1b15 0x1) terminate called throwing an exception(lldb)

2012-04-14 12:17:27.123 CalcTest[27550:f803] *由于未捕获的异常“NSUnknownKeyException”而终止应用程序,

原因:“ [<UIApplication 0x6a14650> setValue:forUndefinedKey:]:此类不符合键值计算器屏幕的键值编码。”

*第一掷调用堆栈:(0x12db022 0x18f8cd6 0x12daee1 0xcc2022 0xc33f6b 0xc33edb 0xc4ed50 0x53671a 0x12dcdea 0x12467f1 0x53526e 0x536eb7 0x313ce1 0x313ff8 0x31317f 0x322183 0x322c38 0x316634 0x27fcef5 0x12af195 0x1213ff2 0x12128da 0x1211d84 0x1211c9b 0x312c65 0x314626 0x1bad 0x1b15为0x1)终止叫做抛出异常(LLDB)

to find the problem, i started a new view based project.

为了找到问题,我开始了一个新的基于视图的项目。

Run the empty new project on the simulator -->works,

在模拟器上运行空的新项目 -->works,

But when I set the main interface, to ViewController, in the summary-->the Simulator crash with

但是当我将主界面设置为 ViewController 时,在摘要中--> Simulator crash with

2012-04-14 12:11:17.492 crash[27494:f803] *Terminating app due to uncaught exception 'NSUnknownKeyException', reason:

'[<UIApplication 0x6a6f4b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.' *First throw call stack:

(0x13c7022 0x1558cd6 0x13c6ee1 0x9bf022 0x930f6b 0x930edb 0x94bd50 0x23371a 0x13c8dea 0x13327f1 0x23226e 0x233eb7 0x10ce1 0x10ff8 0x1017f 0x1f183 0x1fc38 0x13634 0x12b1ef5 0x139b195 0x12ffff2 0x12fe8da 0x12fdd84 0x12fdc9b 0xfc65 0x11626 0x1d4d 0x1cb5) terminate called throwing an exception

2012-04-14 12:11:17.492 崩溃 [27494:f803] *由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:

' [<UIApplication 0x6a6f4b0> setValue:forUndefinedKey:]:该类不符合键视图的键值编码。 *首先抛出调用栈:

(0x13c7022 0x1558cd6 0x13c6ee1 0x9bf022 0x930f6b 0x930edb 0x94bd50 0x23371a 0x13c8dea 0x13327f1 0x23226e 0x233eb7 0x10ce1 0x10ff8 0x1017f 0x1f183 0x1fc38 0x13634 0x12b1ef5 0x139b195 0x12ffff2 0x12fe8da 0x12fdd84 0x12fdc9b 0xfc65 0x11626 0x1d4d 0x1cb5)终止叫做抛出一个异常

is there a solution for the problem?

这个问题有解决方案吗?

回答by Joseph DeCarlo

If you have a control in your nib (xib file) that is linked to a property (IBOutlet) or method (IBAction) in your view controller, and you have either deleted or renamed the property or method, the runtime can't find it because it has been renamed and therefore crashes.

如果您的 nib(xib 文件)中有一个链接到视图控制器中的属性 (IBOutlet) 或方法 (IBAction) 的控件,并且您已删除或重命名该属性或方法,则运行时无法找到它因为它已被重命名,因此崩溃了。

In your case, you have set the Main Interface property of the project to your ViewController.nib. This is a problem because the only nibs that should be used as Main Interface should have UIWindows in them and the File Owner in that nib should be set to the AppDelegate. The UIWindow in the nib should be linked to the File Owner's (AppDelegate) window property. Because you set that with a nib without the traits the runtime was looking for, it gives you this error.

在您的情况下,您已将项目的 Main Interface 属性设置为 ViewController.nib。这是一个问题,因为应该用作主界面的唯一笔尖应该在其中包含 UIWindows,并且该笔尖中的文件所有者应该设置为 AppDelegate。笔尖中的 UIWindow 应链接到文件所有者 (AppDelegate) 的窗口属性。因为你用一个没有运行时正在寻找的特征的笔尖设置它,它会给你这个错误。

The solution is to leave the Main Interface blank as you do not have to set up UIWindows manually anymore.

解决方案是将主界面留空,因为您不必再​​手动设置 UIWindows。

回答by pbeaumier

Just had the same problem and fixed it by right Control-Clicking controls in the xib file to see referencing Outlets. Turned-out that some of the control were still referencing and older name and causing this error to happen.

刚刚遇到了同样的问题,并通过右键单击 xib 文件中的控件来修复它以查看引用的 Outlets。结果发现某些控件仍在引用旧名称并导致发生此错误。

回答by Yohannes Woldemariam

if you get a message similar to:

如果您收到类似于以下内容的消息:

  • Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
  • 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:

'[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key

'[ setValue:forUndefinedKey:]: 此类不是键值编码兼容的键

click the add (+) at the left bottom corner of the BreakPoint navigation area, choose 'add Exception Breakpoint', since it is crashing because of 'NSUnknownKeyException', and opt for 'All'. Run the program. The program stops at the first exception.

单击 BreakPoint 导航区域左下角的添加 (+),选择“添加异常断点”,因为它因“NSUnknownKeyException”而崩溃,并选择“全部”。运行程序。程序在第一个异常处停止。

回答by Diaa Den

try this, select File's Owner then click on the "Connection Inspector" (upper on the top of right pane), you will see all the outlets. Look for any sign like this (!) you will find it on the small circle which indicates a missing outlet, all you have to do is linking it properly or remove the outlet.

试试这个,选择 File's Owner 然后点击“Connection Inspector”(右窗格顶部的上方),你会看到所有的出口。寻找任何这样的标志 (!) 你会在小圆圈上找到它,这表明缺少插座,你所要做的就是正确连接它或移除插座。

回答by Vinay

Try this,

尝试这个,

Go to Target=>Build Phases=>Compile Sources

转到目标 => 构建阶段 => 编译源

Then include 'calculatorScreen.m'

然后包括'calculatorScreen.m'

回答by Yo Solanki

I was facing the same problem. In my case i had renamed the text label in .h file. So there was multiple reference for that label in my main.storyboard file. Once i removed old reference my code started working.

我面临同样的问题。在我的情况下,我重命名了 .h 文件中的文本标签。所以在我的 main.storyboard 文件中有多个对该标签的引用。一旦我删除了旧参考,我的代码就开始工作了。

回答by Krutarth Patel

Please check your target membership select first option.this may help to others

请检查您的目标会员选择第一个选项。这可能对其他人有帮助