显示 UIView 子类 - 此类不符合键的键值编码 [英] Showing a UIView subclass - this class is not key value coding-compliant for the key

查看:29
本文介绍了显示 UIView 子类 - 此类不符合键的键值编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可以从多个视图控制器调用的自定义弹出视图,但我遇到了一些问题.

I am trying to create a custom popup view that can be called from multiple view controllers, but im having some trouble.

只要我从 viewController 本身编写和调用presentPopup"方法,我就能让它正常工作.与其在每个 VC 中编写一个单独的方法,我更愿意在一个单独的类中编写一个方法,然后只传递参数来对其进行个性化设置.

I'm able to get it to work fine as long as I write and call a "presentPopup" method from within the viewController itself. Rather then writing an individual method in each VC, i'd much prefer to write a method in a separate class and just pass parameters to personalize it.

无论如何,每当我尝试这样做时,我都会收到著名的此类与键的键值编码不兼容"错误.只是想知道是否有人对如何使类键值编码合规有任何见解?或者一般如何解决这个问题?谢谢!!

Anyway, whenever I try to do so, I keep getting the famous "this class is not key value coding-compliant for the key" error. Just wondering if anyone had any insights as to HOW to make the class key value coding compliant? Or how to go about this in general?? Thanks!!

推荐答案

在这个答案的最后有一个简单的解释,但我最近看到了一些类似的问题,所以我想我会给出一些背景.

There is a simple explanation at the end of this answer, but I've seen a few similar questions recently so I thought I'd give a bit of background.

错误还应该告诉您哪个键该类不符合键值编码.您的问题的措辞表明您认为可以添加一些通用代码来使类符合键值编码".事实并非如此.

The error should also be telling you which key the class is not key value coding compliant for. The phrasing of your question suggests that you think there is some general bit of code you can add to make a class "key value coding compliant". This isn't the case.

所有可可/可可触摸对象都能够执行键值编码操作.KVC 允许您通过使用 valueForKey:setValue:forKey: 而不是直接使用访问器方法来访问访问器方法.

All cocoa / cocoa touch objects are capable of performing key value coding operations. KVC allows you to reach accessor methods by using valueForKey: or setValue:forKey: instead of using the accessor methods directly.

您看到的错误是:

XXX - 此类不符合键 YYY 的键值编码.

XXX - this class is not key value coding compliant for key YYY.

XXX 是有问题的类,YYY 是关键.所以在某处, [xxx setValue:something forKey:@"YYY"] 正在被调用.

XXX is the class in question, YYY is the key. So somewhere, [xxx setValue:something forKey:@"YYY"] is being called.

此时,您在想但我从未在我的代码中使用过 setValue:forKey!".或许你是对的.但是当您加载 xib 文件时,框架会使用它 - 所有的插座都是使用键值编码设置的.

At this point, you're thinking "but I've never used setValue:forKey in my code!". You may be right. But it is used by the frameworks when you load a xib file - all the outlets are set using key-value coding.

因此,您的 xib 中将有一个出口,该出口连接到已在其链接到的类中删除或重命名的内容.如果幸运的话,它旁边会有一个小小的感叹号.如果你不是,你甚至不会在界面构建器中看到它,你必须编辑 xib 作为源代码并将其从 XML 中删除.

So, you will have an outlet in your xib that is connected to something that has since been removed or renamed in the class it links to. If you're lucky, it will have a little exclamation mark next to it. If you're not, you won't even see it in interface builder and you'll have to edit the xib as source code and remove it from the XML.

这篇关于显示 UIView 子类 - 此类不符合键的键值编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆