I have a Cocoa app with an NSOutlineView
managed by an NSTreeController
.
In addition there's a button for adding new elements to the outline view. I bound the button's enabled
flag to the tree controller's canInsert
property.
I only want to allow adding up to 5 elements to the outline view. After that, canInsert
should return NO
.
I created my own sub-class of NSTreeController
and overwrote canInsert
, but the enabled status of the button does not change, because it doesn't realize that the tree controller has changed when adding elements.
I also implemented: keyPathsForValuesAffectingCanInsert
and tried returning various properties such as content, arrangedObjects
, but no luck here.
@implementation ILCustomTreeController
- (BOOL)canInsert
{
return [[self arrangedObjects] count] < 5;
}
+ (NSSet *)keyPathsForValuesAffectingCanInsert
{
return [NSSet setWithObject:@"content"]; // I also tried 'arrangedObjects'
}
@end