Re: NSImageView subclass, setImage, and bindings
Re: NSImageView subclass, setImage, and bindings
- Subject: Re: NSImageView subclass, setImage, and bindings
- From: Greg Best <email@hidden>
- Date: Sun, 5 Feb 2006 01:33:08 -0800
Hey--
Thanks for the response. I rewrote setMovie as:
-(void)setMovie:(QTMovie*)newMovie
{
NSDictionary* bindInfo=[self infoForBinding:@"value"];
id bindObj=[bindInfo objectForKey:NSObservedObjectKey];
[movie autorelease];
movie=[newMovie retain];
if(movie)
{
if(bindObj)
{
[bindObj setValue:[movie posterImage] forKeyPath:[bindInfo
objectForKey:NSObservedKeyPathKey]];
}
else
{
[self setImage:[movie posterImage]];
}
}
}
It works-- the image gets propagated to the other interested views.
I have to say though, that I'm not entirely comfortable with how (I
think) this is working. The setValue:forKeyPath: call is pushing the
image out to the model, and the NSImageView must be relying on KVO to
read the image back into its local state. This conflicts with how
I'd expect a subclass to operate-- in essence I'd expect it to behave
in a more self contained way by manipulating its state and that of
the parent object directly (or through accessor methods).
As a workaround, this seems to be ok, but I'd feel better if I could
let NSImageView take care of it's own mechanics.
After having typed all of this, I decided to throw together a test
project with two NSImageView's a button and a source image. Both
image views are bound to the same key in the model. If I drag an
image onto one of the views, the other updates correctly. If I use
the button to set one of the views with setImage, the other does not
update. I can't see any other reasonable way to set the image in the
image view... Is this a bug in the NSImageView implementation, or am
I approaching this whole thing wrong?
Cheers--
Greg
On Feb 4, 2006, at 3:57 PM, mmalcolm crawford wrote:
On Feb 3, 2006, at 2:34 AM, Greg Best wrote:
I've subclassed NSImageView (creating MediaWell) with the goal of
being able to receive QuickTime Movies by drag and drop. For now,
I'm only attempting to display the poster frame as the image.
-(void)setMovie:(QTMovie*)newMovie
{
[movie autorelease];
movie=[newMovie retain];
if(movie)
{
[super setImage:[movie posterImage]];
}
}
This works fine within the MediaWell object-- the poster frame
shows as the image in the NSImageView subclass. The problem is
that the binding isn't being triggered so the image is not being
propogated to the model and other views. I've tried calling
setImage on super and self with no difference in behavior (not
that I'd expect any since I haven't overridden the method).
The setImage: method is probably not used to propagate the image to
the object to which the view is bound. See <http://
developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/
Concepts/HowDoBindingsWork.html>...
If you're using Mac OS X v10.3, then you will need to override
bind:toObject:withKeyPath:options: to capture the binding
information to then send the KVC message on update (when the movie
is set); if you're targeting 10.4, then you can simply use
infoForBinding: to retrieve the necessary information (see <http://
homepage.mac.com/mmalc/CocoaExamples/ClockControl2a.zip> for an
example).
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden