setValue:forUndefinedKey this class is not key value coding-compliant for the key
来源:互联网 发布:网络机顶盒电视猫下载 编辑:程序博客网 时间:2024/09/21 09:05
今天在写自定义UITableViewCell的时候遇到一个问题,xib 关联不了类,然后按照网上的步骤:通过设置Flie`s Owner 的custom class 关联上去 ,但是运行直接Crash,报下面的错❌
❎Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key KindsListName.’
然后百度了一下参照这个:点我✅
发现设置完成后还是报上面的错误:表情(一脸的懵逼)(⊙﹏⊙)b
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key KindsListName.’
定位错误原因应该还是自定义xib的问题。
不得已又去:stack overflow 翻看几个谈论如下:PS:看不懂或者不想看直接死命往下翻
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).
大概说的意思问题原因在:MenuTVCell.h 的 outlet 上面。
然后又重新检查了一下自己的控件是不是关联出了问题:
解决办法
果不其然,上面的KindsListName 关联了一个File`s Owner 跟MenuTV Cell 删除一个再运行: OK!
分析原因:
第一次关联的File`s Owne忘记删除了,导致后面的问题。
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- ... setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key latitudeLab
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key解决办法
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lable1.'
- iOS: setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.
- iOS setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 问题
- question:setValue:forUndefinedKey: this class is not key value coding-compliant for the key
- setValue:forUndefinedKey this class is not key value coding-compliant for the key
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- 关于 setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key的另一种错误
- iOS Xcode 6报错:setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key v
- iOS- 报错(崩)[< > setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- ViewController 0x8f35e00> setValue:forUndefinedKey:]: this class is not key value coding-compliant f
- [Linux] 刚学习shell,碰到问题.执行时总出错:unexpected operator(转载)
- Android Activity(一)初识
- 分布式锁的实现
- 实战CGLib系列文章 MethodInterceptor和Enhancer
- Android Gradle Plugin与Gradle 版本对应关系
- setValue:forUndefinedKey this class is not key value coding-compliant for the key
- Python自然语言处理-第一章总结:语言处理与Python
- Ext success和failure
- 修改oracle11g所有用户密码使其永不过期
- civetweb作为radosgw的agent的处理机制
- Go语言下使用 nats 消息机制
- Git submodule 如何删除一个 submodule
- BitMap(位图)
- linux使用nmon监控、分析系统性能