Re: Core Data Bindings Issue
Re: Core Data Bindings Issue
- Subject: Re: Core Data Bindings Issue
- From: Quincey Morris <email@hidden>
- Date: Wed, 18 Aug 2010 18:26:04 -0700
On Aug 18, 2010, at 18:00, Frank D. Engel, Jr. wrote:
> I have a controller class which is represented as a simple object (cube icon) in Interface Builder. This class has an "id" field to which I assign various instances of core data entities (represented by a subclass of NSManagedObject by selecting them in an NSBrowser whose delegate is the controller class.
>
> I then have an NSSlider and an NSCheckbox which both have their value bindings bound to the same field of the selected object, via the controller class; in other words:
>
>
> @interface MyBrowser : NSObject
> {
> id selectedWhatever;
> }
>
> - (id)selectedWhatever;
> - (void)setSelectedWhatever:(id)whatever;
>
>
>
> Then the "value" bindings of the NSSlider and NSCheckbox are both "selectedWhatever.someField".
>
>
> The problem I am having is that if I move the slider, the value of the field does not change right away, but if I select something else and then select the modified entity again (changes selectedWhatever to something else and back), the field shows the modified value.
>
> It almost seems as if the slider is not sending updates to the entity until the entity is about to change?
>
> Similarly, if I edit the value in the text field, the slider does not move until I select something else then come back.
>
> How can I get the text field and slider to update in sync with each other?
>
>
> If it helps, the class being used for the "selectedWhatever" values has the field defined as:
>
> @property float someField;
Since your property is declared to have a scalar (float) value, it must be a custom accessor of your custom NSManagedObject subclass. (Core Data's internally-provided properties are all object values, never scalars.) See "Scalar Values" in:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html#//apple_ref/doc/uid/TP40001919-SW13
That means you've probably forgotten to implement KVO compliance in the setter for this property. (Overridden Core Data setters must invoke didChange/willChangeValueForKey: explicitly.) See "Custom Implementation" in:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154-SW1
_______________________________________________
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