NSUnknownKeyException的解决方法

来源:互联网 发布:黑龙江省干部网络教育 编辑:程序博客网 时间:2024/06/07 23:30

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key itemName.'

使用的是NIB文件/界面生成器,此错误消息的真正含义是:在NIB文件中有一个ui元素通过IBOutlet连接到了controller中的某一个对象,但是该对向不存在。

我遇到的时候,我没有修改任何变量,仅仅时添加了一个函数,这样也发生了这个问题,我不知道具体时哪个变量的Outlet那有问题,所以我把之前的所有连接都删除了,重新连接就可以了。

官方文档:
If you're using NIB files / Interface Builder, what this error message REALLY means is:

"Your NIB file has a GUI element that's connected (via the Outlets screen) to an outlet in one of your source files that doesn't exist"

i.e. it usually happens when you change the name of an IBOutlet variable in your source file, and forget to change your NIB file to reflect the change.

(sadly, Interface Builder isn't good enough to automatically rename the connection, as it is supposed to do - you MUST do it manually)

原创粉丝点击