Re: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?
Re: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?
- Subject: Re: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?
- From: Kyle Sluder <email@hidden>
- Date: Fri, 2 Apr 2010 22:33:59 -0700
On Fri, Apr 2, 2010 at 8:25 PM, Jerry Krinock <email@hidden> wrote:
> I solved the problem by eliminating all this code and binding my button's 'enabled' binding instead to the array controller's 'selection' and, to my surprise, it worked. My surprise is because, according to superclass NSObjectController documentation, 'selection' returns NSNoSelectionMarker when there is no selection, not nil which is what my NSIsNotNil value transformer would expect.
While this works (I imagine that -[NSButtonCell setObjectValue:]
treats NSNoSelectionMarker specially) I would think that the "right"
thing to do would be to subclass NSArrayController and write a
-canPerformFoo method. But you would need to self-observe the
selection property, which is perilous because
-removeObserver:forKeyPath: doesn't take a context argument (another
bug every Cocoa developer should file a duplicate of). So you could
use MAKVONotificationCenter (or OFBinding, our analogue) to
self-observe. Perhaps it would be easier to instead put the
-canPerformFoo method on your window controller.
--Kyle Sluder
_______________________________________________
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