Re: Bindings to enable a menu item based on an array's element count
Re: Bindings to enable a menu item based on an array's element count
- Subject: Re: Bindings to enable a menu item based on an array's element count
- From: Ken Thomases <email@hidden>
- Date: Sun, 07 Sep 2014 06:02:23 -0500
On Sep 7, 2014, at 5:15 AM, Daryle Walker <email@hidden> wrote:
> Right now, the menu item that holds the submenu where the overflow menu items go is always visible. I was thinking of controlling its visibility with Cocoa Bindings. I select the menu item in the Interface Builder part of Xcode, go to the Bindings Inspector, reveal the Hidden attribute settings, and set the binding to my app’s delegate. Under the Model Key Path, I put “self.my2ndCoordinator.overflowArray”. Now, that’s an array and I need a Boolean. I tried “.count” and “.@count” at the end, and neither worked.
What does "neither worked" mean? What happened?
".@count" should work. ".count" would not. That effectively attempts to construct an array by asking each _element_ of overflowArray for its "count" property, which is always the way that KVC on arrays works. This will probably fail because the elements don't have a count property and even it succeeds, it would result in an array which is not an appropriate result for the hidden binding.
(Also, starting a key path with "self." is just redundant.)
> Even then, I still need to stick in the “> 0” part somewhere (unless Bindings does the zero vs. non-zero to Boolean conversion C does).
I don't know that I'd describe it as bindings "doing" that "conversion", but, yes, in a boolean context, 0 means false and non-zero means true. Since you presumably want the menu to be hidden when the count is 0, you want to use the NSNegateBoolean value transformer set on the binding.
Regards,
Ken
_______________________________________________
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