• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Bidirectional, Manual Binding in custom control
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bidirectional, Manual Binding in custom control


  • Subject: Re: Bidirectional, Manual Binding in custom control
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 27 Jun 2012 22:12:23 -0700

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 (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


  • Follow-Ups:
    • Re: Bidirectional, Manual Binding in custom control
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Handling "Smart Zoom" gesture?
  • Next by Date: Re: Bidirectional, Manual Binding in custom control
  • Previous by thread: Re: Handling "Smart Zoom" gesture?
  • Next by thread: Re: Bidirectional, Manual Binding in custom control
  • Index(es):
    • Date
    • Thread