• 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: NSTextView's "data" binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView's "data" binding


  • Subject: Re: NSTextView's "data" binding
  • From: Yann Bizeul <email@hidden>
  • Date: Mon, 30 Apr 2007 00:50:00 +0200

Now I see different documentations on how to implement bindings in custom views (includng your GraphicsBindings) and I'm a bit confused/disappointed :

Do you want to use a custom view, or NSTextView?
I'd like to use my NSView subclass, which contains a NSTextView

In almost every examples I saw, it seems that I have to implement KVO myself in
- (void)bind:(NSString *)bindingName
toObject:(id)observableObject
withKeyPath:(NSString *)observableKeyPath
options:(NSDictionary *)options


It's not clear what you mean.
In your bind method, you must add yourself as an observer of an object to which you are bound. That doesn't seem unreasonable or an imposition of a significant overhear -- it's one method call.
Yes, but what I do not understand is I never registered as an observer for the model object property (my NSManagedObject) but this part of the binding is working. my NSView's does receive new values when they are changed. What does not work is, when properties changes in my view, the model object is never updated.

What looks surprising to me is that to implement binding in a custom NSView object, you have to manually implement KVO in bound object, and when your view changes a bound value, it looks like I have to keep track of observed objects by myself. I don"t see why NSObject does not implement this.

This looks like a big overhead to me (add myself as observer, manage change notifications, do call observers when modification are made in the view, ...)

Thanks for the hand

Yann Bizeul - yann at tynsoe.org
Cocoa Developer

Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/


Le 30 avr. 07 à 00:28, mmalc crawford a écrit :


On Apr 29, 2007, at 3:04 PM, Yann Bizeul wrote:

Now I see different documentations on how to implement bindings in custom views (includng your GraphicsBindings) and I'm a bit confused/disappointed :

Do you want to use a custom view, or NSTextView?


In almost every examples I saw, it seems that I have to implement KVO myself in
- (void)bind:(NSString *)bindingName
toObject:(id)observableObject
withKeyPath:(NSString *)observableKeyPath
options:(NSDictionary *)options


It's not clear what you mean.
In your bind method, you must add yourself as an observer of an object to which you are bound. That doesn't seem unreasonable or an imposition of a significant overhear -- it's one method call.



but I thought NSObject was KVO compliant so that when I willChangeValue / didChangeValue, it was responsabile of annoucing the chages to every observers, automatically setup in bind;toObject:withKeyPath:options: implementation of NSObject.

An object that is KVO compliant does send KVO notifications to objects that are registered observers. Typically you don't have to do anything yourself to support this -- see <http:// developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/Concepts/AutoVsManual.html>.


If you're not sure which way round bindings work, I would strongly suggest re-reading the documents I cited earlier and trying some of the more basic tutorials before spending more time on implementing a custom view. I would then suggest looking at the Joystick example (<http://developer.apple.com/samplecode/BindingsJoystick/>) which is a full implementation of the example used in the documentation. It shows what observation you need to set up in the bind:... method, and how to implement the observe... method.


mmalc



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >NSTextView's "data" binding (From: Yann Bizeul <email@hidden>)
 >Re: NSTextView's "data" binding (From: mmalc crawford <email@hidden>)
 >Re: NSTextView's "data" binding (From: mmalc crawford <email@hidden>)
 >Re: NSTextView's "data" binding (From: Yann Bizeul <email@hidden>)
 >Re: NSTextView's "data" binding (From: mmalc crawford <email@hidden>)

  • Prev by Date: Re: NSTextView's "data" binding
  • Next by Date: Re: Memory management/freeing with delegate methods
  • Previous by thread: Re: NSTextView's "data" binding
  • Next by thread: Re: NSTextView's "data" binding
  • Index(es):
    • Date
    • Thread