Re: Returning a Boolean in a NSValueTransformer
Re: Returning a Boolean in a NSValueTransformer
- Subject: Re: Returning a Boolean in a NSValueTransformer
- From: Jim Correia <email@hidden>
- Date: Sat, 24 Sep 2005 10:04:57 -0400
On Sep 24, 2005, at 9:51 AM, Dario Mèndez Musicò wrote:
I'm developing an application wich makes massive use of Cocoa
Bindings to display data.
I never had any particular problems, but now I'd need to make an
NSButton appear enabled or disabled whenever a value is somethning
or not.
So I set up an NSValueTransformer to pick up a string value from my
data and perform an isEqualToString: command.
If the string is "N/A" i should return NO in order to make the
NSButton disabled, else i'll return YES.
However this method doesn't work and crashes my app, it also issues
warnings about maiking pointer from integer without a cast.
The lingua franca of value transformers are objects, not scalar
values. Your transformed value class is [NSNumber class] and you
should be returning [NSNumber numberWithBool: YES] (or no as
appropriate.)
That said, while it answers your question, I don't think this is the
best way to go about solving
I'd need to make an NSButton appear enabled or disabled whenever
a value is somethning or not.
this problem.
You should need to use value transformers to do this. (And in fact,
having to register/name one value transformer per condition doesn't
feel very scalable.)
If you have a button "Go to Next Page" bind it to canGoToNextPage,
and have your canGoToNextPage method return YES or NO based on the
current condition. canGoToNextPage will either have to be registered
as a dependent key for whichever keys affect the condition, or you'll
have to manually invoke will/didChangeValueForKey: @"canGoToNextPage"
in the appropriate places.
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden