Re: NSArrayController subclass computed property not being updated
Re: NSArrayController subclass computed property not being updated
- Subject: Re: NSArrayController subclass computed property not being updated
- From: Alexander Heinz <email@hidden>
- Date: Tue, 28 Jul 2009 22:40:41 -0700
I may not have made myself clear enough: I need objects bound to this
property to be notified whenever the selection of the array controller
changes, much like the existing "canAdd:" and "canRemove:" properties
of NSArrayController. This property has nothing to do with whether or
not the array controller CAN change the index set; the default
behavior of removeSelection: is fine with me.
- Alex
On Jul 28, 2009, at 10:29 PM, Chase Meadors wrote:
I'm assuming you've written an accessor that makes the appropriate
judgments based on selectionIndex and selectionIndexes. It's not
getting called, however, because the framework doesn't know it's
there! I would override removeSeletion: like so:
- (void)removeSelection:(NSIndex *)index { //maybe not exact
wording, but whatever
if ([self canRemoveSelection]) {
[super removeSelection:index];
}
}
On Jul 29, 2009, at 12:09 AM, Alexander Heinz wrote:
Hello all,
I've got an NSArrayController subclass with a computed property:
@property (readonly) BOOL canRemoveSelection;
(This basically adds some application-specific checks to the
canRemove: property, so that I can bind a "remove" button in
Interface Builder.)
I want the property to be recomputed every time the
"selectionIndex" or "selectionIndexes" of the array controller
change, so, in my ".m" file, I have:
+ (NSSet*)keyPathsForValuesAffectingCanRemoveSelection
{
return [NSSet setWithObjects:@"selectionIndex",
@"selectionIndexes", nil];
}
(I realize this is probably redundant, but bear with me.)
However, the accessor for the property (i.e., "-
(BOOL)canRemoveSelection") is never called, beyond the initial call
when the object is created. As a result, the button bound to the
property never changes state.
I've checked to make sure that -setSelectionIndexes: is being
called, and it is, but the property is not re-computed.
Does anyone see anything immediately wrong here?
- Alex
_______________________________________________
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