Is NSTableView sortDescriptors KVO compliant?

  • Hello,

    I have an NSTableView subclass and I want to use KVO to detect when
    the sort descriptors change so that I can save them.  The idea is
    that when the user comes back to the table the columns will be sorted
    the same way they last saw them.

    Here's the addObserver call:

    [self addObserver: self forKeyPath: @"tableView.selectionIndexes"
    options:NSKeyValueObservingOptionNew context:self];
    [self addObserver: self forKeyPath: @"tableView.sortDescriptors"
    options:NSKeyValueObservingOptionNew context:self];

    For testing here's my observeValueWithKeyPath method:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)
    object change:(NSDictionary *)change context:(void *)context;
    {
    NSLog(keyPath);
    }

    In the log see "selectionIndexes" but I never see "sortDescriptors".
    This leads me to believe that sortDescriptors is not KVO compliant,
    but its listed in the bindings reference for NSTableView http://
    developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/
    BindingsText/NSTableView.html

    Adhamh
  • On Dec 13, 2007, at 6:21 PM, Adhamh Findlay wrote:

    > I have an NSTableView subclass and I want to use KVO to detect when
    > the sort descriptors change so that I can save them.  The idea is
    > that when the user comes back to the table the columns will be
    > sorted the same way they last saw them.
    > Here's the addObserver call:
    >
    > [self addObserver: self forKeyPath: @"tableView.selectionIndexes"
    > options:NSKeyValueObservingOptionNew context:self];
    > [self addObserver: self forKeyPath: @"tableView.sortDescriptors"
    > options:NSKeyValueObservingOptionNew context:self];
    >
    No, you should be observing the object to which the table view's
    sortDescriptors property is bound (typically the array controller --
    see <http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/B
    indingsText/NSTableView.html#//apple_ref/doc/uid/NSTableView-DontLinkElemen
    tID_621
    >).  The general point is that you don't observe views -- views are
    the things that do the observing.

    > This leads me to believe that sortDescriptors is not KVO compliant,
    > but its listed in the bindings reference for NSTableViewhttp://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/B
    indingsText/NSTableView.html

    >
    Similar to the previous point, the bindings reference lists properties
    that can be bound, not those that are observable.

    mmalc
  • On Dec 13, 2007, at 9:37 PM, mmalc crawford wrote:

    >> This leads me to believe that sortDescriptors is not KVO compliant,
    >> but its listed in the bindings reference for NSTableViewhttp://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/B
    indingsText/NSTableView.html

    >>
    > Similar to the previous point, the bindings reference lists
    > properties that can be bound, not those that are observable.

    Yes.  The Bindings Reference is NOT the same as the class reference.

    To expand slightly on mmalc's info. (and hopefully not confusing the OP)

    Unless stated otherwise in the documentation you should not assume
    that any of the AppKit/Foundation/Core Data/etc.. properties are
    observable.

    The controller properties that ARE observable are listed here:
    http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Art
    icles/ControllerKey-ValueObservingCompliance.html#/

    /apple_ref/doc/uid/TP40002493

    Some additional observable exceptions are noted in NSViewController,
    NSCollectionView and NSPrintPanelAccessorizing
  • On Dec 14, 2007, at 12:38 AM, Scott Anguish wrote:

    >
    > Yes.  The Bindings Reference is NOT the same as the class reference.
    >
    >
    > To expand slightly on mmalc's info. (and hopefully not confusing
    > the OP)
    >
    > Unless stated otherwise in the documentation you should not assume
    > that any of the AppKit/Foundation/Core Data/etc.. properties are
    > observable.
    >
    >
    > The controller properties that ARE observable are listed here:
    > http://developer.apple.com/documentation/Cocoa/Conceptual/
    > CocoaBindings/Articles/ControllerKey-
    > ValueObservingCompliance.html#//apple_ref/doc/uid/TP40002493
    >
    >
    > Some additional observable exceptions are noted in
    > NSViewController, NSCollectionView and NSPrintPanelAccessorizing

    Thanks Scott, this is very useful.

    Adhamh
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today