• 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: NSImageView subclass, setImage, and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImageView subclass, setImage, and bindings


  • Subject: Re: NSImageView subclass, setImage, and bindings
  • From: mmalcolm crawford <email@hidden>
  • Date: Sun, 5 Feb 2006 09:42:43 -0800


On Feb 5, 2006, at 1:33 AM, Greg Best wrote:

-(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]];
}
}
}


This isn't the pattern the documentation or the other example illustrates. You shouldn't update the bound-to object in the setter, you should perform updates in response to user action. (See also <http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaBindings/Concepts/Troubleshooting.html#//apple_ref/doc/uid/ TP40002148-182467>.)

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).

I'm not sure I understand your concern. The role of the view is to reflect the value in the model (again see <http://developer.apple.com/ documentation/Cocoa/Conceptual/CocoaBindings/Concepts/ Troubleshooting.html#//apple_ref/doc/uid/TP40002148-182467>).

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


References: 
 >NSImageView subclass, setImage, and bindings (From: Greg Best <email@hidden>)
 >Re: NSImageView subclass, setImage, and bindings (From: mmalcolm crawford <email@hidden>)
 >Re: NSImageView subclass, setImage, and bindings (From: Greg Best <email@hidden>)

  • Prev by Date: Re: NSOutlineView Row Selection Color
  • Next by Date: Re: first steps
  • Previous by thread: Re: NSImageView subclass, setImage, and bindings
  • Next by thread: ceil woes
  • Index(es):
    • Date
    • Thread