I'm trying to have a custom subclass of NSTableView observe the value of its own -selectedRowIndexes
property, and I'm having trouble figuring out how to receive the notifications properly. My subclass looks like this (using ARC):
@implementation MyTableView
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self addObserver:self forKeyPath:@"selectedRowIndexes" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:NULL];
}
return self;
}
- (void)dealloc {
[self removeObserver:self forKeyPath:@"selectedRowIndexes"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"change: %@", change);
}
@end
However, I never see -observeValueForKeyPath:...
get called. Am I missing something?
I'm also open to a better solution - the reason I want to do KVO rather than relying on the delegate's -tableViewSelectionDidChange:
method is that I'd like both the previous and current values for selectedRowIndexes
, rather than just being able to get the current selection. If there's a way to do that without KVO on this property, I'm all ears.