简体   繁体   English

查找键值编码路径

[英]Finding Key-Value Coding Paths

Key-value coding paths are useful in UIKit. 键值编码路径在UIKit中很有用。 They often allow you to configure elements that aren't specified in the public API of a view, or in the Interface Builder inspector for that view. 它们通常允许您配置在视图的公共API或该视图的Interface Builder检查器中未指定的元素。

For instance, you can configure the text color of UIDatePicker using textColor key path, but there doesn't seem to be a property or method exposing that configuration -- the only way to do it is through key-value coding. 例如,您可以使用textColor键路径配置UIDatePicker的文本颜色,但是似乎没有暴露该配置的属性或方法-唯一的方法是通过键值编码。

Given that -- how can one as an iOS developer find key-value coding paths for elements? 鉴于此-作为iOS开发人员,如何才能找到元素的键值编码路径? I found this particular example in a StackOverflow response, but how did they find it? 我在StackOverflow响应中找到了这个特定示例,但是他们如何找到它呢? I'd love to be able to inspect these classes and find their key-value coding paths myself, or at least have a good crowdsourced reference to all the KVC key paths that might be useful when I'm trying to customize a view. 我很想能够自己检查这些类并找到它们的键值编码路径,或者至少对所有KVC密钥路径都有很好的众包引用,这在我尝试自定义视图时可能很有用。

You can use class-dump to view all properties on an Objective-C class, including private properties (properties with the _ underscore prefix) 您可以使用类转储查看Objective-C类的所有属性,包括私有属性(带有_下划线前缀的属性)

But also yes as @rmaddy said, most of the time you won't want to modify private properties-- but it should be pretty safe if you are just reading and not writing. 但也正如@rmaddy所说,是的,大多数时候您都不想修改私有属性-但如果您只是阅读而不是写作,那应该是相当安全的。 For example, NSUndoManager has a private property, _undoStack , which is super useful to read so you can see what is currently in your undo stack 例如, NSUndoManager具有一个私有属性_undoStack ,它对于读取超级有用,因此您可以查看撤消堆栈中当前包含的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM