Re: what is a bindings pattern to check for a non-empty selection?
Re: what is a bindings pattern to check for a non-empty selection?
- Subject: Re: what is a bindings pattern to check for a non-empty selection?
- From: Jerry Krinock <email@hidden>
- Date: Fri, 19 Feb 2010 05:15:20 -0800
On 2010 Feb 19, at 03:02, Jean-Denis Muys wrote:
> I am trying to bind the button's "Enabled" property to the ArrayController so that I get whether something is selected (multiple selections allowed).
In code, write a simple subclass of NSValueTransformer, nonreversible, which transforms an array to a BOOL, returning YES if the array is nonempty. Add it to your project, then specify it in the binding. Search Xcode documentation for "Value Transformer Programming Guide" and read it.
> I have tried bindings to selectedObjects using the model key "count", as a non zero count is obviously compatible with the BOOL that the property expects. But this doesn't work: I get an error message:
>
> "Cannot create BOOL from object () of class __NSArray0"
It means that it wants a BOOL but the selectedObjects you're giving it is an array.
> I really don't understand that error message, as the count message returns an integer, not an object. Can anybody explain?
In this case, there is no object involved.
> I finally manage to use the "canRemove" key of the arrayController.
Cute trick.
> It seems to work, but I feel nervous about it. I don't like the name of it. Of course at first glance, it seems you can't remove unless you have a non-empty selection, but other conditions may apply (not locked, whatever).
I agree; it does look rather fragile.
> So is the "canRemove" the commonly accepted practice to test for a non empty selection in an table view using an NSArrayController?
I wouldn't ship it.
> Is there a reason for NSArrayController (or NSObjectController for that matter) not to have a "hasSelection" predicate available?
Probably because Apple has 5 million bugs open and not many people have requested this.
> Or is there another better pattern?
Value Transformer.
> (though the question is in the context of an table view and an NSArrayController, it might possibly be asked in a wider context).
Same answer.
_______________________________________________
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