NSTableView auto sorting does not work

  • I have experienced that an NSTableview which is bound to an array controller will sometimes automatically sort when their column headers are clicked and sometimes not. As an example, I currently have two windows, each with a tableview bound to an array controller. One tableview sorts, the other does not. For both tableviews each column is bound to the arranged objects of its respective array controller and has "Creates Sort Descriptor" selected in IB.Yes, I could use delegates and implement my own sort descriptors but getting free sorting is really nice and it works for some of my tableviews, so I'd like to find out what breaks this functionality.
  • On Fri, Feb 11, 2011 at 5:14 PM, Chris Tracewell <chris...> wrote:
    > I have experienced that an NSTableview which is bound to an array controller will sometimes automatically sort when their column headers are clicked and sometimes not. As an example, I currently have two windows, each with a tableview bound to an array controller. One tableview sorts, the other does not. For both tableviews each column is bound to the arranged objects of its respective array controller and has "Creates Sort Descriptor" selected in IB.Yes, I could use delegates and implement my own sort descriptors but getting free sorting is really nice and it works for some of my tableviews, so I'd like to find out what breaks this functionality.

    Did you actually bind the table view's sortDescriptors binding to the
    array controller's sortDescriptors property?

    In the simplest case (all columns bound to different keys on the same
    NSArrayController), NSTableView will automagically bind its
    selectedIndexes and its sortDescriptors bindings to the relevant
    properties on the array controller. But if your columns aren't all
    bound to the same array controller, the table view can't logically do
    this, so you are responsible for binding these yourself.

    --Kyle Sluder
  • > Did you actually bind the table view's sortDescriptors binding to the
    > array controller's sortDescriptors property?
    >

    No, but that's why I posted, trying to figure out when this can be avoided.

    > In the simplest case (all columns bound to different keys on the same
    > NSArrayController), NSTableView will automagically bind its
    > selectedIndexes and its sortDescriptors bindings to the relevant
    > properties on the array controller. But if your columns aren't all
    > bound to the same array controller, the table view can't logically do
    > this, so you are responsible for binding these yourself.

    This is helpful, thanks for explaining. I am however, using only one NSArrayController between all of the columns and am not using any display patterns (I noticed they do not offer the "Creates Sort Descriptor" option). At this point I could just move on and set my Array Controller's sortDescriptor property but it just really bugs me to not know what line I am crossing that disables the automagic functionality.

    --Chris
  • > On Fri, Feb 11, 2011 at 5:14 PM, Chris Tracewell <chris...> wrote:
    >> I have experienced that an NSTableview which is bound to an array controller will sometimes automatically sort when their column headers are clicked and sometimes not. As an example, I currently have two windows, each with a tableview bound to an array controller. One tableview sorts, the other does not. For both tableviews each column is bound to the arranged objects of its respective array controller and has "Creates Sort Descriptor" selected in IB.Yes, I could use delegates and implement my own sort descriptors but getting free sorting is really nice and it works for some of my tableviews, so I'd like to find out what breaks this functionality.
    >

    I got this to work. I noticed in Tableview 1 that I never bound its content or selectionindexes to the array controller, only the actual columns were bound and automatic sorting worked. In tableview 2 I had those two properties bound and when I unbound them automagic sorting began working. I assume that since I had set the selectionIndexes and content properties of the tableview the automagic sortDescriptor creation and binding assumed I was taking over and stopped doing their thing. Also worthy of noting is that binding using display patterns on tv columns will also break auto sorting. That was fine for me as it made sense to provide a property via my model anyway.

    I would really appreciate anyone pointing me to docs that explain this if it exists so I can be confident in my assumptions.

    --Chris
previous month february 2011 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            
Go to today