• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPopupButton and content values binding transformer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPopupButton and content values binding transformer


  • Subject: Re: NSPopupButton and content values binding transformer
  • From: "email@hidden" <email@hidden>
  • Date: Mon, 28 Oct 2013 13:09:02 +0000

On 26 Oct 2013, at 21:28, email@hidden wrote:

> On 25 Oct 2013, at 10:58, email@hidden wrote:
>
>> Value transformers applied to NSPopupButton have some idiosyncrasies.
>> http://stackoverflow.com/questions/12505764/nspopupbutton-bindings-with-value-transformer
>>
>> I have applied a transformer to an NSPopupButton content values binding but the IB configured transformer does not seem to be applied.
>> I am not alone in this: http://macscripter.net/viewtopic.php?id=39496
>>
>> If I log the binding the transformer is present.
>> However, if I enter an invalid transformer name the app does not raise (which it should).
>> If I then log the binding with the invalid name then it does raise.
>>
> The initial scenario was:
>
> 1. NSPopUpButton Content bound to arrayController.arrangedObjects
> 2. NSPopUpButton Content values bound to arrayController.arrangedObjects.name
> 3. A value transformer that returns NSString applied to the Content values binding.
>
> This initial scenario does indeed ignore the value transformer.
>
This one is a conversation with myself. However:

My adopted workaround to this is:

1. Remove the non functional transformer from the content values binding.
2. Define a category method on the objects returned by arrayController.arrangedObjects:

@implementation MyObject (MyCat)
- (NSString *)transName
{
    return [self extValueForKey:@"name" withTransformerForName:@"MyTransformer"];
}
@end


3. Define the value for key transformer extension method:

@implementation NSObject (MyCat)
- (id)extValueForKey:(NSString *)key withTransformerForName:(NSString *)transformerName
{
    return [[NSValueTransformer valueTransformerForName:transformerName] transformedValue:[self valueForKey:key]];
}
@end

4. NSPopUpButton Content values bound to arrayController.arrangedObjects.transName

This work around is compatible with the Content Objects and Selected Object bindings.

The approach is acceptable I feel for custom classes where a category method has limited scope.
I wouldn't want to utilise it in the case say of an NSDictionary binding.

Jonathan


_______________________________________________

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


References: 
 >NSPopupButton and content values binding transformer (From: "email@hidden" <email@hidden>)
 >Re: NSPopupButton and content values binding transformer (From: "email@hidden" <email@hidden>)

  • Prev by Date: BridgeSupport files
  • Next by Date: MultiBinding
  • Previous by thread: Re: NSPopupButton and content values binding transformer
  • Next by thread: Autolayout wrt Cassowary
  • Index(es):
    • Date
    • Thread