How do I validate value of a reverse transform input field in Cocoa?

Scenario:

  • Two text input fields FieldA and FieldB
  • Value is stored in a single variable Var
  • Value of FieldA can be derived from the value of FieldB and vice versa (think C vs F)
  • There is a Value Transformer defined that converts from A to B and also reverse converse from B to A .
  • FieldA is bound to Var via Object Controller (model key path is pointing to Var )
  • FieldB is also bound to Var (mop is set to Var ), but also has Value Transformer defined.
  • So this works fine. If I type in something in FieldA , FieldB gets updated and if I type something in FieldB , FieldA gets updated accordingly.

    Now I want to do some field validation work. So I:

  • Define validateVar
  • Tick validates immediately in the IB on FieldA
  • So far so good. If I type in rubbish in FieldA , validateVar returns NO and I get a nice error message.

    $1M question is, how do I validate the FieldB after it has changed?

    I cannot (really) rely on the fact that B converts to A and if A is invalid I get a message.

    My thinking is to do the validation in the reverse value transform function and return something that falls out of the validateVar range, but I think this isn't very nice.

    Is there a way to do something like validateFieldB ?

    PS. validateVar gets called with reverse transformed value from FieldB , so effectively the FieldB is transformed to FieldA value and then FieldA calls the validation function.

    PPS. OS X Lion. XCode 4.1.

    链接地址: http://www.djcxy.com/p/85270.html

    上一篇: 初始化可可IB绑定

    下一篇: 如何验证Cocoa中反向变换输入字段的值?