Re: Trouble binding against transient Core Data property
Re: Trouble binding against transient Core Data property
- Subject: Re: Trouble binding against transient Core Data property
- From: Rick Mann <email@hidden>
- Date: Mon, 11 Oct 2010 14:41:29 -0700
On Oct 10, 2010, at 22:31:47, Quincey Morris wrote:
> One way or another, you're going to have to come up with code to handle both directions of frame change: model-to-view and view-to-model. One approach is to use KVO observance (via [view bind:@'frame" toObject:vp withKeyPath:@"frame" options:0] if you really want to -- note the change of direction) for one direction, and have a controller object (such as a view controller or window controller) observe frame-change notifications from the view and update the model property directly.
Thanks for the attempt to explain this all to me. I wish I were smart enough to understand it. I had assumed that -bind:... was short for "establish KVO in two directions," but clearly that's not the case. I thought that if the two properties were KVC/KVO-compliant, things would just work.
Since each plug-in must subclass NSViewController in order to provide a view to display, I can provide a custom NSViewController subclass for them to use, and put whatever code is necessary into that. But it's not clear to me exactly what I would do, then.
The SimpleBindingsAdoption_02 sample app does this:
NSObjectController *controller = [[[NSObjectController alloc] init] autorelease];
[controller bind:@"contentObject" toObject:self withKeyPath:@"track" options:nil];
[textField bind:@"value" toObject:controller withKeyPath:@"selection.volume" options:nil];
[slider bind:@"value" toObject:controller withKeyPath:@"selection.volume" options:nil];
NSViewController has a "representedObject" property that it claims can be used for binding, I wonder if I can point that at the plug-in instance and bind through that property. Guess it's worth a try...
[view bind: @"frame" toObject: controller withKeyPath: @"representedObject.frame" options: nil];
And, nope. Now the value in the model puts the view in the specified place, but changing the view's frame does not propagate the change to the model. Does that mean that -[NSView frame] is not KVC-compliant, or that I still need custom code somewhere to create the binding?
--
Rick
_______________________________________________
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