On 2012 May 21, at 21:52, Quincey Morris wrote:

> On May 21, 2012, at 20:44 , Jerry Krinock wrote:

>> -(void)setRating:(float)rating
>> {
>>    // Stuff to make reverse binding work…
>>    NSDictionary* bindingsInfo = [self infoForBinding:@"rating"] ;
>>    id object = [bindingsInfo objectForKey:NSObservedObjectKey] ;
>>    NSString* bindingsPath = [bindingsInfo objectForKey:NSObservedKeyPathKey] 
>> ;
>>    [object setValue:[NSNumber numberWithFloat:rating]
>>          forKeyPath:bindingsPath] ;
>> 
>>    // Set ivar, needsDisplay
>>    …
>> }
> 
> This seems more or less the correct approach to defining a custom binding. 
> "More or less" because you may have committed some minor technical violation 
> of custom binding implementations, described unintelligibly in this document:
> 
>       
> https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html

So, five weeks later, I learn that I probably was committing a minor technical 
violation.

Pushing a value into the data model whenever a value is set in the view is not 
a good idea.  Such a push will occur, for example, whenever the selection 
changes, which is of course not necessary.  In fact, it can do some damage…

Tonight I modified my Inspector to support editing values in a multiple 
selection, for example:

• Select 10 model objects.
• Inspector indicates "Multiple Selection".
• Click the 3rd star in the Inspector's Star Rating View.
• I might put a warning sheet here, "Are you sure you want to change 10 items, 
blah?"
• All 10 objects get a 3-star rating.

But after I bound instead to a "multiFoo" class to make that work, I found that 
the extra setting of the data model was causing model values to be copied from 
one model object to the next when the I simply selected one model object and 
then changed the selection to a different model object.

A better place for pushing the value to the data model is in the input-handling 
method of the view, -mouseDown: in the case of my star rating control.  Moving 
the above code to -mouseDown: fixed the problem.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to