Re: Binding NSTextField to an array
Re: Binding NSTextField to an array
- Subject: Re: Binding NSTextField to an array
- From: Jeremy Hughes <email@hidden>
- Date: Mon, 06 Mar 2017 16:44:22 +0000
> On 6 Mar 2017, at 14:30, Jonathan Mitchell <email@hidden> wrote:
>
> Sounds like NSValueTransformer is in fact what you need.
> It can take in your NSArray ref and spit out a single NSString that the NSTextField binding can live with.
I think I must be missing something obvious.
The value of an NSTextField can be bound (in Interface Builder) to a property in File’s Owner or to an array controller that is bound to a property in File’s Owner. There is a checkbox in Interface Builder that says “Allows Editing Multiple Values Selection”.
This suggests to me that I can bind a text field to an array or (if that's not possible) to an array controller that is bound to the array. If there are multiple values, the controller should return NSMultipleValuesMarker, which according to Apple’s documentation "indicates that more than one object is selected in the controller and the values for the requested key aren’t the same.”
The documentation goes on to say "For example, if the value for selection.name returns an array containing three strings—”Tony”, “Tony”, “Tony”—the string “Tony” is returned instead of the NSMultipleValuesMarker.”
What I’m trying to do is to display a textfield (with a number formatter) which should display an integer value (such as “7”) if all the values in the array are the same, or a multiple-values indicator (like “-“) if the values are not the same.
I can get the binding to work if I bind the text field to a single value, but I can’t get it to work with an array of values or with an array controller that is bound to an array of values.
Maybe I should give up on using bindings to do this, but it would be good to understand what I’m doing wrong.
Jeremy
_______________________________________________
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