ios 如何解决“NSUnknownKeyException”... setValue:forUndefinedKey:]: ...不符合键值编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11118135/
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
How do I solve a 'NSUnknownKeyException' ... setValue:forUndefinedKey:]: ...not key value coding compliant
提问by ipatch
Alright, I'll try and make this brief as possible. I wanted to a UIToolbar above my keyboard, and it took me a while to figure it out, and I eventually did, but when I tried adding function to the buttons previous*next* and donemy program would soon not compile.
好的,我会尽量简短。我想在我的键盘上方添加一个 UIToolbar,我花了一段时间才弄明白,我最终做到了,但是当我尝试将功能添加到上一个* 下一个 *按钮并完成时,我的程序很快就无法编译。
The entire error message can be seen here:
整个错误信息可以在这里看到:
2012-06-20 05:36:55.276 KegCop[79460:fb03] *Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key done.'
*First throw call stack: (0x134a022 0x1733cd6 0x1349ee1 0xd31022 0xca2f6b 0xca2edb 0xcbdd50 0x5a571a 0x134bdea 0x12b57f1 0x5a426e 0x7adeef 0x7ae03e 0x382d7a 0x382ff8 0x38217f 0x391183 0x391c38 0x385634 0x1f84ef5 0x131e195 0x1282ff2 0x12818da 0x1280d84 0x1280c9b 0x381c65 0x383626 0x2a8d 0x29f5 0x1) terminate called throwing an exception(lldb)
2012-06-20 05:36:55.276 KegCop[79460:fb03] *由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:该类对于完成的键不符合键值编码.'
*第一掷调用堆栈:(0x134a022 0x1733cd6 0x1349ee1 0xd31022 0xca2f6b 0xca2edb 0xcbdd50 0x5a571a 0x134bdea 0x12b57f1 0x5a426e 0x7adeef 0x7ae03e 0x382d7a 0x382ff8 0x38217f 0x391183 0x391c38 0x385634 0x1f84ef5 0x131e195 0x1282ff2 0x12818da 0x1280d84 0x1280c9b 0x381c65 0x383626 0x2a8d 0x29f5为0x1)终止叫做抛出异常(LLDB)
@Abizern suggested I should read the Apple Doc on Key value coding guide. Anyways it's super late, or super early however you look at it. The updated project can be found here: https://github.com/ipatch/KegCop
@Abitern 建议我应该阅读Apple Doc on Key value coding guide。不管怎样,无论你怎么看,它都超级晚了,或者超级早了。更新后的项目可以在这里找到:https: //github.com/ipatch/KegCop
Just download the zip, and try and build and you will see what I am talking about. The error probably lies somewhere in the ViewControllerWelcome.mfile.
只需下载 zip,然后尝试构建,您就会看到我在说什么。该错误可能位于ViewControllerWelcome.m文件中的某个位置。
回答by Phillip Mills
Look in your storyboard or xib (whichever you're using) for the ViewControllerWelcome
object. The most likely source of this error is that something has a connection to an action or outlet called done
that doesn't exist in the code for that class.
在您的故事板或 xib(无论您使用哪个)中查找该ViewControllerWelcome
对象。此错误的最可能来源是某个操作或插座done
与该类的代码中不存在的操作或插座相关联。
回答by kaskader
The easiest way to check that is to Ctrl+Click on your Controller in the Storyboard View and look for something in the resulting popup which has a yellow warning mark next to it. Simply delete it by pressing the (x) next to the Outlet name.
最简单的检查方法是在 Storyboard 视图中按住 Ctrl+单击您的控制器,然后在生成的弹出窗口中查找旁边有黄色警告标记的内容。只需按插座名称旁边的 (x) 即可将其删除。
回答by Sauvik Dolui
If you are using a storyboard then just click on every ViewController and select the connections inspector of them. Check whether there exit any exclamatory sign(for lost connections).
如果您使用的是故事板,那么只需单击每个 ViewController 并选择它们的连接检查器。检查是否有任何感叹号(对于丢失的连接)。
Delete them properly.Then run your project again.
正确删除它们。然后再次运行您的项目。
回答by user2380132
I have encountered the same problem, I used a xib for the viewcontroller but then I deleted it. However in the code,the connection still get connections from the deleted xib. So the way to walk around is create a new xib for the viewcontroller. Then problem solved.
我遇到了同样的问题,我为 viewcontroller 使用了 xib,但后来我删除了它。但是在代码中,连接仍然从已删除的 xib 获取连接。因此,四处走动的方法是为视图控制器创建一个新的 xib。然后问题解决了。
回答by user2387149
In my case it was some weird cache on xcode, even with all the removed references to the IBOutlets was still making it crash. IBOutlets were pointing to a older version of my file so not even removing and adding back files or removing all referencing outlets from my nib worked...
就我而言,这是 xcode 上的一些奇怪缓存,即使删除了对 IBOutlets 的所有引用,它仍然会崩溃。IBOutlets 指向我的文件的旧版本,所以甚至没有删除和添加回文件或从我的笔尖中删除所有引用插座工作......
SOLUTION:
closing xcodemade the trick, also cleaning/deepCleaning the projectmight have helped.
SOLUTION:
关闭 xcode成功了,清理/深度清理项目也可能有所帮助。
回答by lorry lee
For my situation I added -all_load
in "Other Linker Flags" to prevent Xcode from stripping my library binary code.
对于我的情况,我添加-all_load
了“其他链接器标志”以防止 Xcode 剥离我的库二进制代码。