Re: Using multiple bindings to enable a button
Re: Using multiple bindings to enable a button
- Subject: Re: Using multiple bindings to enable a button
- From: Quincey Morris <email@hidden>
- Date: Wed, 11 Feb 2015 06:31:52 +0000
On Feb 10, 2015, at 21:45 , Steve Mills <email@hidden> wrote:
>
> I'm not sure about the KVO compliancy. I'm still a newbie in this area. Let me give you the rundown on the stuff that deals with it.
>
> @interface WindController : NSWindowController
> @property (weak) NSString* comboStringValue;
> @end
>
> The window has:
>
> A Combobox binds its Value to File's Owner.self.comboStringValue, because I've learned you can't bind directly to a field's stringValue.
As a general rule, if you bind a control’s value to a model property, the model property is updated KVO compliantly. (But you don’t need the “self.” in there. It has no practical effect whatsoever.)
However, a weak property is never KVO compliant, because its value can potentially change (to nil) at any time, without going through the property setter, which is what supplies the KVO compliance.
One possible scenario is that the combo box updates its binding using a copy of its own value. In that case, your “comboStringValue” property would be set, then shortly afterwards would change to nil, when the update releases the last reference to the string copy. Depending on the timing, one or both of these changes would be reflected to the “Enabled2” binding for the button — that is, the button might see it as nil or not nil.
Try changing the “comboStringValue” property to strong. Anyway, it makes no sense for it to be weak. (An IBOutlet reference to a control in a nib can be weak, because the window controller owns all the top level objects in the nib, so everything in the nib is already owned by something or other.)
If that doesn’t solve the problem, you need to start investigating (via NSLogging, probably) whether the “comboStringValue” property has the correct value at all times — and that really means the property value, not the NSComboBox objectValue property: don’t rely on what you *see* in the UI. If it doesn’t, all the bindings in the world aren’t going to help you.
> A button binds its Enabled to File's Owner.self.comboStringValue.length.
>
> Another button binds its Enabled to Keywords Array Controller.selection.@count and its Enabled2 to File's Owner.comboStringValue.length.
>
> The 2nd button is the one that doesn't behave when the bindings are in that order. Swapping them fixes it. I've tried swapping them back to the original orientation multiple times, and it always fails to work properly when they're in that order.
_______________________________________________
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