NSView Docs. Was: Binding -- or not -- a button created in code
NSView Docs. Was: Binding -- or not -- a button created in code
- Subject: NSView Docs. Was: Binding -- or not -- a button created in code
- From: Jerry Krinock <email@hidden>
- Date: Mon, 21 Jun 2010 19:53:19 -0700
On 2010 Jun 21, at 00:35, Kyle Sluder wrote:
> On Mon, Jun 21, 2010 at 12:14 AM, Jerry Krinock <email@hidden> wrote:
>> In a home-made "collection view", each item contains a checkbox, whose value should represent an attribute in the data model.
>
> So, you are going to have multiple checkbox-style NSButtons
> (NSCollectionView approach), not just cell-based drawing
> (NSMatrix/NSTableView approach)?
Yes. I realize this is more expensive, but it allows differences among the "collection" items which seem to be not possible in either cells or NSCollectionViewItem objects. In particular, I need a popup menu to have different menu items enabled/disabled in each "collection" item.
> -viewWillMoveToWindow: sounds like it might fit the bill; unbind if
> the argument is nil.
Good idea, Kyle. So I just wrote a subclass of NSView which "manages bindings of its subviews". Instead of sending bind:toObject:keyPath:options, you send a similar message to this view (the bound object's superview), which instead remembers the binding parameters, and keeps them bound whenever the view is in a window and unbound otherwise. I suppose that Cocoa Bindings does similar stuff for us under the hood when bindings are set in Interface Builder.
It works, but the documentation for -viewWillMoveToWindow: states only that it
"Informs the receiver that it’s being added to the view hierarchy of the specified window object (which may be nil)."
My lawyer says this does not guarantee that -viewWillMoveToWindow: will be sent when a window will be *closed*. In my system, it does. Alternatively, a statement that "If a window is closed, its view tree is moved to a nil window", would suffice.
But does anyone know of any Apple documentation which states this behavior in plain language?
_______________________________________________
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