Re: Adding bindings to a custom view - "simple" implementation
Re: Adding bindings to a custom view - "simple" implementation
- Subject: Re: Adding bindings to a custom view - "simple" implementation
- From: Ricky Sharp <email@hidden>
- Date: Mon, 17 Apr 2006 12:10:07 -0500
On Monday, April 17, 2006, at 11:03AM, George Orthwein <email@hidden> wrote:
>Hi All,
>I've searched extensively and haven't quite seen this addressed....
>I've added bindings support to my custom view following Hillegass's
>lead (pg 385) by merely implementing setBindingName: and bindingName:
>methods. He states there is seldom need to override
>bind:toObject:withKeyPath:options:. It all seems to be working great
>and my view is kept in sync with the controller/model.
>
>e.g. in my view:
>
>- (void)setHeaderHeightBinding:(id)height;
>{
> [self setHeaderHeight:height];
>}
>
>- (id)headerHeightBinding;
>{
> return headerHeight; //an aside: "return NULL;" here doesn't seem
>to cause any problems...
>}
>
>So this seems quite a contrast to the much more complicated joystick
>example (or mmalc's GraphicsBindings) which implements
>bind:toObject:withKeyPath:options in the view along with several
>other methods:
>http://developer.apple.com/documentation/Cocoa/Conceptual/
>CocoaBindings/Concepts/HowDoBindingsWork.html
>
>Is it okay to use the "short" version? My view isn't a control so it
>isn't initiating any updates. It looks like the "long" way would
>allow more flexibility as well as NSEditorRegistration, but I don't
>seem to need those for my view.
Don't know what pitfalls (if any) will exist with the "short" method above.
The sample code that hit home for me was mmalc's joystick sample. All my custom controls and views (along with associated palettes) was modeled off that sample. Perhaps it may be extra code in my views (which never initiate changes themselves), but I like having the same pattern of implementation used throughout my codebase.
It's also been very easy to add new bindings over time. A simple search on an existing binding shows me all places that I need to wire the new one in.
Finally, from your comment above about NULL values... you may want to implement setNilValueForKey so that you can return sane (default) values for your various attributes.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
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