Re: transformers? revisited but getting there..
Re: transformers? revisited but getting there..
- Subject: Re: transformers? revisited but getting there..
- From: Tod Cunningham <email@hidden>
- Date: Mon, 20 Sep 2004 22:08:20 -0400
You can create your own transfer derived from NSValueTransformer. You
have to register the transformer in the application before it can be
used. The following is a sample value transformer that I made. It
transformers one String into another string. You could supply any data
you wish to the customer transform when it is created.
@implementation QRZCallsignTransformer
+ (QRZCallsignTransformer *)registerTransformer
{
NSString *transformerName = [QRZCallsignTransformer
className];
QRZCallsignTransformer *callsignTransformer;
callsignTransformer = (QRZCallsignTransformer *)[NSValueTransformer
valueTransformerForName:transformerName];
// Create and register custom transformer if necessary
//
if( callsignTransformer == nil )
{
callsignTransformer = [[[QRZCallsignTransformer alloc] init]
autorelease];
[NSValueTransformer setValueTransformer:callsignTransformer
forName:transformerName];
}
return callsignTransformer;
}
+ (Class)transformedValueClass
{
return [NSString class];
}
+ (BOOL)allowsReverseTransformation;
{
return NO;
}
- (id)transformedValue:(id)value
{
if( value == nil || ![value isKindOfClass:[NSString class]] )
return nil;
return [[QRZLib findCallsign:value] fullName];
}
- (id)reverseTransformedValue:(id)value;
{
return( nil );
}
@end
On Sep 20, 2004, at 8:09 AM, Theodore Petrosky wrote:
Thanks Tod,
I had just seen a few posts that spoke of using the
index...
It appears to me that a tranformer is not really a
'class' that I can access. A better solution (if
available) is to create the transformer, them pass it
the values to transform after I query the database. I
can not figure out how to talk to the transformer..
Is this possible?
Ted
--- Tod Cunningham <email@hidden> wrote:
You could definitely use a two way transformer to do
this, but as as
you mentioned the transformer would be an issue if
you don't know the
mapping of clientnames to clientcodes without the
database query. You
could also query the arraycontroller to get the
selected object and
then extract the clientcode yourself:
CLLogEntry *contact = [[logArrayController
selectedObjects]
objectAtIndex:0];
int code = [contact clientcode];
This assume your arraycontroller returns an object
of type CLLogEntry,
but just use whatever class arraycontroller is
mapped to return (such
as NSMutableDictionary. You can then get the
selected clientcode and
do whatever you want with it.
Remember to bind the contentArray of the controller:
[logArrayController bind:@"contentArray"
toObject:logBook
withKeyPath:@"logEntryList" options:nil];
Hope that helps a little, you could also easily do a
one way transform
from CLLogEntry to int (code) if that helps you!!!
- Tod
On Sep 19, 2004, at 12:32 PM, Theodore Petrosky
wrote:
I need some help with transforms and bindings.
a little history:
I have a popup managed by an arraycontroller. the
array is created by querying a database and
retrieving
a list of clientnames and clientcodes. I then bind
the
clientnames to the popup. my problem is that when
I
change the popup, I need the clientcode to be
updated
in the selection.loggedInByCode in the main
controller.
I have used NSTransformers for this before however
I
don't know how to get the transform values into
the
transformer.
The question is, am I barking up the wrong tree
with
using the transformerValues.
Is there an easier way to bind the clientNamePopUp
in
such a way that if I select a new clientname, the
clientcode gets updated also.
my 'schema' is like this.
mainJobArray =
jobNumber
clientNmae
clientCode
loggedindate
proofdate
finaldate
the popupcontroller is bound to:
clientname
clientcode
where I am displaying the clientname in the popup.
This array is created on the fly from the database
and
can change so I can not create a transformer that
is
hard coded.
Am I clear? How can I accomplish this?
Ted
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
_______________________________________________
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