Cocoa KVC:“类不是关键值编码兼容” [英] Cocoa KVC: "class is not key value coding-compliant"
问题描述
我想用KVC更新一些属性。
I'm trying to update some properties with KVC. The properties have been synthesized.
此行适用于:
myObject.value = intValue;
这不起作用:
[self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"];
并且爆炸:由于未捕获异常NSUnknownKeyException终止应用程序,原因: [< MyViewController 0xd1cec0> setValue:forUndefinedKey:]:此类不是键myObject.value的键值编码。
And blows up with: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyViewController 0xd1cec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myObject.value.'
(awakeFromNib)相同类的其他实例响应正确setValue:forKey:调用。唯一的区别是这个特定的实例是在IB中创建和连接的。
Yet further up the method (awakeFromNib) other instances of the same class respond fine to setValue:forKey: calls. The only difference is this particular instance was created and wired up in IB.
推荐答案
它告诉你那个对象不是一个有效的键,事实上它不是:myObject.value 是一个键,而不是单个键。
It's telling you that isn't a valid key for that object, and indeed it isn't: "myObject.value" is a keypath, not a single key.
这篇关于Cocoa KVC:“类不是关键值编码兼容”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!