On 20/04/2011, at 19:07, Joanna Carter wrote: >> Your value transformer, if you insist on doing it that way, should be coded >> to expect this, and should transform an entire array of strings, not single >> strings. > > I got the impression that the array in question could hold unprintable > characters (tab, etc) and that the transformer was to make them into > human-readable strings (@"TAB"). There is certainly no problem with > displaying lists of strings via the Content binding, whether it is through an > array controller or not. > > But, you reckon that the transformer for the binding has to transform the > whole array? Hmmm, now I'm going to have to try that out :-)
I tried it out and returning the whole array from the transformer made the
pop-up button look as I wanted it! Thanks everyone, I thought it was a team
effort here -- nice work. Note that I used:
popupButton.contentValues -(Transformer)-> [arrayController].arrangedObjects
That said, I do think it's inconsistent with the way that I expected the pop-up
button bindings to work. I'll put together a simple example and send it to
bugreporter.
The code I wound up using in the transformer looks like:
- (NSString *)transformString:(NSString *)value
{
return ([value length] == 1) ? [NSString stringWithFormat:@"%C (%04x)",
[value characterAtIndex:0], [value characterAtIndex:0]] : value;
}
- (id)transformedValue:(id)value
{
if ([value respondsToSelector:@selector(characterAtIndex:)])
return [self transformString:value];
else if ([value respondsToSelector:@selector(objectAtIndex:)]) {
NSMutableArray *a = [NSMutableArray array];
for (id v in value)
[a addObject:[self transformString:v]];
return [NSArray arrayWithArray:a];
} else
return value;
}
I figure if the way this is handled changes at some stage, the code should
continue to work.
Thanks again.
Ben.
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
