On Oct 12, 2010, at 16:15:17, Quincey Morris wrote:

> My advice: Forget you ever started thinking about bindings. Forget about the 
> 'bind...' method. Go back to the basics. You have objects two classes that 
> have a "frame" property that need to be kept in sync. Use 
> 'addObserver:forKeyPath:...' and 'observeValueForKeyPath:...' in an object 
> suitably placed to be an observer (e.g. your view controller, or possibly 
> your view) of both. Write code to make sure that a change in one property is 
> reflected as a change in the other. Forget that this thread ever existed. :)

Okay, I did that. In the end, I created a notification I send at the end of my 
dragging operation (the user can reposition a plug-in's view on the canvas), 
and I use that to update the model.I KVObserve changes in the model and update 
the view, which handles the initial load and undo.

Side note: I had initially KVObserved the view, as well, which worked fine, but 
resulted in very large undo stacks with nearly every pixel of movement 
recorded. I could have (and probably should have) grouped the operations 
between the mouse down and the mouse up of the dragging operation, but I wasn't 
entirely sure that there wouldn't be other operations I'd make available during 
a drag (I know, it's a long shot, but the thinking stems from a different app 
I'm working on where that's possible). It does mean, however, that other 
operations that move the view (for example, nudging with arrow keys) will have 
to be sure to send the notification as well so I may go the other way. In fact, 
the more I think about it, the more I think I will.

Thanks again for your help. I still don't understand how/when to create custom 
bindings, especially when using -bind:…, and I'd like to for a complex custom 
view in a manner similar to NSTableView, but that's for a different day.

P.S.--It seems reasonable to create a category method on NSObject, call it 
-link:…, that does what I had expected -bind:… to do, don't you think? Set up 
the KVO necessary to keep to KVO-compliant properties in sync.

-- 
Rick

_______________________________________________

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

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

Reply via email to