下午开发过程中遇到一个错误,结果被的真惨,从上午 11 点查错一直查到下午 2 点才找到错误的原因,真的郁闷的不行。

关于查错这么久,主要的原因是:
 

1. 自己对 IOS 开发还不熟悉
2. 不知道怎么得到错误的详细信息, 连调出来 All Output 面板查看错误信息都不知道,真的差劲
3. 有错误信息后应该直接去 stackoverflow 找答案。应为 IOS 开发中文方面的资料和分享实在太少,出错就要直接上 stackoverflow.

 
下面说错误,错误的详细信息:
 

2013-07-12 15:49:43.476 MyPad[15944:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<BenefitItemsTableCell 0x6d9bdd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key.'
*** First throw call stack:
(0x1490022 0x127fcd6 0x148fee1 0xd90022 0xd01f6b 0xd01edb 0x420c88 0xd1cd50 0x60471a 0x1491dea 0x13fb7f1 0x60326e 0x475230 0xd886e94 0x65ea1 0x47cc54 0x47d3ce 0x468cbd 0x4776f1 0x420d42 0x1491e42 0x23e679 0x248579 0x1cd4f7 0x1cf3f6 0x25c160 0x3e0e84 0x3e1767 0x3f0183 0x3f0c38 0x3e4634 0x2329ef5 0x1464195 0x13c8ff2 0x13c78da 0x13c6d84 0x13c6c9b 0x3e0c65 0x3e2626 0x1a0ad 0x2535)
terminate called throwing an exception(lldb)

其中出错的代码在:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCustomerTableCell"; // 这行代码运行出错
MyTableCell *cell =(MyTableCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; ....
return cell;
}

关于这个奇怪的错误,在 stackoverflow 找到了这样的解释:

There are a couple of options to resolve this - i'll let you decide which is the most appropriate.

The reason it's failing is because the owner is being passed as nil. You're binding the actionText outlet to the file's owner in IB, but then when loading the nib, the owner is nil. I'd guess that when loading with a nil owner behind the scenes an NSObject is used, which is why you're getting the key/value error.

My previous advice to pass the cell as the owner would also fail as I didn't know how the Nib is constructed; the cell is nil as you've yet to create it (and dequeue is passing nil back, so even pass cell as the owner is still essentially passing nil).

Two options:

Instantiate a new cell in your -cellForRowAtIndexPath:(NSIndexPath *)indexPath implementation, and pass that new cell as the owner (but i'd guess that this isn't the best solution for you)
Or, and I'd suggest this is the better solution, change the binding of actionText in your nib file to the Alert Cell and not the file's owner (You have File's Owner and an Alert Cell - bind the UILabel to the actionText outlet of the Alert Cell, and not the File's owner, which is what's being done at present) - I suspect this is what you want. With that in mind file's owner can become an NSObject again.
------- Original answer kept below as the file's owner class is also a common cause for this error -------

It suggests that you've 'instantiated' an AlertCell in InterfaceBuilder, and you're binding something to actiontext, but the class isn't set to AlertCell, it's still NSObject?

Take a look at the class text box on the identify tab of the tool palette for that object in Interface Builder. The class should be AlertCell, but i'd guess it's still set to NSObject.

As an aside, and feel free to ignore this advice, but there are a couple of extra things i'd encourage you to do, purely from an Objective C expectations/conventions point of view:

Name your files after your class (upper case the first character of the filename).
Prefix your class names; two uppercase characters, typically your initials (i'd name it DWAlertCell, for example).

我这英文,也只能勉强看个大概,最后知道了原因在那里:MyTableCell.h 中的 outlet 上面。

去代码中一查,果然原因在这里。这是因为我 从 StoryBoard 中连接好 outlet 后又手工的在 MyTableCell.h 中更改了outlet 的名字,之后重新连接了 outlet,本来以为这样万事大吉,可是却从 StoryBoard 中逐个检查 Controller 的 outlet  后,发现我重命名的 outlet 那个控件上面之前的 outlet 没有删掉,和新添加的  outlet同事存在,郁闷,这是 XCODE bug 吗。

删掉老的 outlet 后,万事大吉,郁闷,烦!

所以这样的错误,就去检查 StoryBoard 中的 outlet。

setValue:forUndefinedKey this class is not key value coding-compliant for the key的更多相关文章

  1. 'NSUnknownKeyException' … setValue:forUndefinedKey:]: …not key value coding compliant

    解决一个问题: 当我添加一个IBout, 报了如下错误 NSUnknownKeyException' … setValue:forUndefinedKey:]: …not key value codi ...

  2. reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key value c

    reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key v ...

  3. iOS: setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.

     这里指抛出一个假设:   如 果你在 storyboard中, 通过 Ctrl - Drag 方式声明了一个 @property , 但你又觉得 在 Ctrl - Drag 时 ,命名的proper ...

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

    *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ViewController > ...

  5. '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]

    Bug如下: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUnd ...

  6. setValue:forUndefinedKey

    *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewControlle ...

  7. iOS key value coding kvc在接收json数据与 model封装中的使用

    iOS key value coding  kvc在接收json数据与 model封装中的使用 使用 kvc 能够极大的简化代码工作,及以后的接口维护工作: 1:先创建MovieModel类.h和 . ...

  8. 公钥(Public Key)与私钥(Private Key)

    公钥(Public Key)与私钥(Private Key)是通过一种算法得到的一个密钥对(即一个公钥和一个私钥),公钥是密钥对中公开的部分,私钥则是非公开的部分.公钥通常用于加密会话密钥.验证数字签 ...

  9. ssh无密码登录设置方法以及出现问题 ECDSA host key 和IP地址对应的key不同的解决

    最近在做hadoop,因为要求各主机之间的用户必须相同,且为方便远程登录,需配置无密码登录 先附上ssh无密码登录设置方法: 先生成密钥并配置无ssh无密码登录本机,输入命令: ssh-keygen ...

随机推荐

  1. bzoj3680模拟退火

    看题意就是一道数学物理题,带权费马点   --这怎么是数学了,这也是物理的 所以要用物理方法,比如FFF 国际著名oi选手miaom曾说 模拟退火初温可以低,但是最好烧个几千次 国际著名物理课代表+1 ...

  2. Shader实例:溶解效果(Dissolve)

    效果: 图左:一道金光闪过,瞬间灰飞烟灭 图右:燃烧效果,先过渡到黄色,然后渐渐过渡到黑色,最后消失殆尽. 这是游戏中常见的效果,各位可以想想自己玩过的游戏. 手头正在玩的,梦三国手游,死亡的时候就是 ...

  3. js学习笔记

    javacript笔记根据EC5.0一共有六种数据类型:number,string,bool undefine,nullobject(广义的) --->object(狭义的),array,fun ...

  4. Java 应该跨四个平台

    编程语言从属于操作系统,要统一,就要在根本处统一,要统一的是操作系统,而不是编程语言.你认为是苹果决定苹果树,还是苹果树决定苹果? 编程语言跨操作系统是错误的道路,你见过苹果长在桔子树上的吗?苹果长得 ...

  5. JS中原型链继承

    当我们通过构造函数A来实现一项功能的时候,而构造函数B中需要用到构造函数A中的属性或者方法,如果我们对B中的属性或者方法进行重写就会出现冗杂的代码,同时写出来也很是麻烦.而在js中每个函数都有个原型, ...

  6. 创建Chrome启动器

    今天清理垃圾时不知怎么把chrome启动器删除了,现在要重新创建一个 1.在桌面创建一个chrome.exe的快捷键方式,属性更改目标为: "C:\Program Files (x86)\G ...

  7. sqlplus运行sql文件

    当sql文件的数据比较多的时候,pl/sql运行比较慢,可以通过oracle的sqlplus进行导入: sqlplus user/password@tnsname@sqlfile.sql; 注意如果文 ...

  8. 数字对象NSNumber

    //将int类型转化成对象 ; NSNumber *numberString = [NSNumber numberWithInt:number]; //对象是可以放入数组的 NSArray *arra ...

  9. Spring4 实例

    结构目录如下: 其中: dao层和entity层都属于hibernate的的管辖.entity层里面装的是每张表对应的持久化类.dao层里面装的是"底层操作数据库的行为",仅仅只是 ...

  10. CF2.D

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...