可可绑定的NSHandlesContentAsCompoundValueBindingOption到底做什么? [英] What does Cocoa binding's NSHandlesContentAsCompoundValueBindingOption do exactly?

查看:95
本文介绍了可可绑定的NSHandlesContentAsCompoundValueBindingOption到底做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSArrayController 的contentArray绑定到 NSUserDefaultsController 时,必须检查将内容作为复合处理值复选框。这已经成为传统的常识,但是该选项实际上是做什么的?

When binding an NSArrayController's contentArray to an NSUserDefaultsController, you have to check the "Handles Content As Compound Value" checkbox on the binding. This has become conventional wisdom, but what does the option actually do?

我写了一个小型测试应用程序,可以观察到,打开该选项后,整个<$ c每当您编辑数组中元素的属性时,都会将$ c> contentArray 传递给绑定源的 setValue:forKey:。禁用该选项时,仅修改元素对象本身,并且不通知绑定源。

I wrote a small test app and could observe that with the option turned on, the whole contentArray is passed to the binding source's setValue:forKey: whenever you edit a property of an element in the array. When the option is off, only the element object itself is modified and the binding source is not notified.

这说明了为什么需要使用该选项来生成 NSUserDefaultsController 工作(否则它不会注意到您已经编辑了数组中的某些内容,并且从不保存更改)。但这并不能解释谁在完全不同地做什么。阵列控制器在观察到更改时是否负责此选项并写回内容阵列?如果是这样,它与该选项的既定目的有何关系?该目的是使用可逆值转换器暂时将复合值转换成较小的部分?

This explains why the option is needed to make NSUserDefaultsController work (otherwise it wouldn't notice that you had edited something in the array and never save the change). But it doesn't explain who is doing what differently exactly. Is the array controller taking charge of this option and writing back the content array when it observes a change? If so, how does it relate to the stated purpose of the option which is to "use a reversible value transformer to translate [...] compound values temporarily into smaller pieces"?

推荐答案

此处很好地说明了消息流: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html #// apple_ref / doc / uid / TP40002149-186285

The message flow is explained here pretty well: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html#//apple_ref/doc/uid/TP40002149-186285

这是我的尝试:


  1. contentObject contentArray 或<$ c $指定的原始内容对象使用 valueForKeyPath:

  2. 从NSUserDefaultsController中检索c> contentSet 绑定。值转换器的 transformedValue: m ethod

  3. 将来自用户的新值插入到转换后的内容对象中

  4. 使用 inverseTransformedValue对内容对象进行逆转换:

  5. 将新的,经过逆变换的内容对象设置为新的内容对象,并使用 setValue:forKeyPath:<传递给NSUserDefaultsController。 / code>

  1. The original content object specified by the contentObject, contentArray or contentSet binding is retrieved from the NSUserDefaultsController using valueForKeyPath:
  2. That content object is transformed using the value transformer's transformedValue: method
  3. The new value from the user is inserted into the transformed content object
  4. The content object is inverse transformed using inverseTransformedValue:
  5. The new, inverse transformed content object is set as the new content object and passed to the NSUserDefaultsController using setValue:forKeyPath:

这篇关于可可绑定的NSHandlesContentAsCompoundValueBindingOption到底做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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