Re: Trying to bind to reverseTransformedValue: in IB
Re: Trying to bind to reverseTransformedValue: in IB
- Subject: Re: Trying to bind to reverseTransformedValue: in IB
- From: "Kyle Sluder" <email@hidden>
- Date: Sat, 26 Jan 2008 22:25:59 -0500
On Jan 26, 2008 9:52 PM, Sam Stigler <email@hidden> wrote:
> The problem I'm running into is that although by far the most
> straightforward way for me to set this up would be to bind to the
> reverseTransformedValue: method of at least one of the transformers, I
> have no idea how I would go about setting that up in IB. Is it
> possible? I'm guessing that as is, if I bind a variable to a text
> field in IB using a value transformer, the transformedValue: method
> will be used. Am I right about that?
A value transformer is essentially a function which maps values of one
type to values of another type. If you can supply the inverse
function as well, then you do so using -allowsReverseTransformation
and -reverseTransformedValue:. This allows Cocoa to use your value
transformer to set values as well as transform them, but the reverse
transformation is actually a function (in the mathematical sense).
So for your app, you would probably want to store an NSNumber as your
model. Then, you would have three value transformers that would
essentially be the following functions: Number --> String (base 10),
Number --> String (base 16), Number --> String (base 2). You would
provide the reverse transformations in these value transformers as
well, since there is a functional relationship between a string of
digits and a number. Cocoa will use the model type --> view type
binding (Number --> String) for display, and then use the inverse
(String --> Number) for storage.
So your question about "binding reverseTransformedValue" doesn't make any sense.
HTH,
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden