Re: Binding NSMenuItem 1 to 1
Re: Binding NSMenuItem 1 to 1
- Subject: Re: Binding NSMenuItem 1 to 1
- From: Jeff Johnson <email@hidden>
- Date: Wed, 22 Aug 2007 10:24:39 -0500
On Aug 21, 2007, at 8:50 AM, Knut Lorenzen wrote:
Jeff Johnson (email@hidden) schrieb dereinst
(am
21.08.2007 1:30 Uhr):
I believe that you can get the desired effect by setting your
enabled
binding's Multiple Values Placeholder to YES.
(Should be No as communicated by private mail)
You can also set the No Selection Placeholder to NO. You probably
don't need the "@count" keypath; you can probably just use the
Value
Transformer "NSIsNotNil".
Got it working now. Here is the trick:
- Model Key Path must *not* be @count, using an arbitrary Key works
- Value Transformer set to NSIsNotNil
- Multiple Values Placeholder set to No
This seems convoluted and fragile -- what happens if the selected
object has no value for 'arbitraryKey'? What happens if your
model changes -- will you remember that that binding was
dependent on 'arbitraryKey'?
It would be more robust and expressive to bind to, say, the array
controller' selectionIndexes (which is KVO compliant and provides
exactly the information you require) and determine whether the
count of the selected indexes is 1 using a value transformer...
mmalc
I agree that the arbitrary key is fragile. My thought was just to
use the array controller's "selection", without any other key. If
there's no selection or multiple selections, it will return the
appropriate placeholder. Otherwise, just check whether selection
is non-nil.
-Jeff
On second thought, "selection" alone seems not to work. However,
using the key "self" with "selection" does work.
Another approach would be to use "canRemove" rather than "selection".
In any case, the Multiple Values and No Selection placeholders
should be NO.
-Jeff
Caveat: "selection.self" won't necessary work with objects that
override "valueForKey:", such as NSDictionary.
Correction: "canRemove" doesn't return multiple value placeholders,
so that won't work.
I think that mmalc's solution should work in all cases, though it
does require code outside of Interface Builder.
-Jeff
_______________________________________________
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