trouble keeping NSTableView sorted

  • Hello,

    To keep a NSTableView contents sorted I believe I need to bind the
    table's sortDescriptors to the array controller the table is bound
    to. If so, I am not doing it right because I get the following errors
    on startup:

    *** -[NSCFString key]: selector not recognized [self = 0x327b60]
    *** NSRunLoop ignoring exception '*** -[NSCFString key]: selector not
    recognized [self = 0x327b60]' that raised during posting of delayed
    perform with target 381920 and selector 'invokeWithTarget:'

    The table's sortDescriptor binding is set to:
        Bind to: MyController
        Controller Key: arrangedObjects
        Model Key Path: name

    "name" is the key to the NSString value of the objects MyController
    handles.

    Thank you!
    Gonzalo
  • on 12/7/07 7:48 AM, <Gonzalo.Castro...> purportedly said:

    > Hello,
    >
    > To keep a NSTableView contents sorted I believe I need to bind the
    > table's sortDescriptors to the array controller the table is bound
    > to.

    Depends on what you mean by "keeping sorted", although your approach is
    incorrect for just about any interpretation.

    If you mean that you want a set sort order that the user can't change, then
    bind the tablevew's selectionIndexes to the array controller. This will
    disable column header sorting.

    Sort descriptors are implicitly bound, so you don't have to be concerned
    about them. Just make sure the array controller has the correct sort
    descriptors already set.

    > Bind to: MyController
    > Controller Key: arrangedObjects
    > Model Key Path: name
    >
    > "name" is the key to the NSString value of the objects MyController
    > handles.

    If the above isn't simply a random stab in the dark, you really need to
    re-read the bindings documentation and examples, as well as the docs on
    NSSortDescriptor. The above seems to show that you aren't clear on either.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • > If you mean that you want a set sort order that the user can't
    > change, then
    > bind the tablevew's selectionIndexes to the array controller. This
    > will
    > disable column header sorting.

    Untrue: by nib awakening the table will be sorted according to the bound
    sort descriptors array but the user can still click on a column header
    to sort
    the array differently.

    If you want this to be disabled you’ve got to uncheck the Create sort
    descriptors
    binding option for each column value binding.

    Flofl.
  • on 12/7/07 1:11 PM, <wdyp...> purportedly said:

    >> If you mean that you want a set sort order that the user can't
    >> change, then
    >> bind the tablevew's selectionIndexes to the array controller. This
    >> will
    >> disable column header sorting.
    >
    > Untrue: by nib awakening the table will be sorted according to the bound
    > sort descriptors array but the user can still click on a column header
    > to sort
    > the array differently.
    >
    > If you want this to be disabled you¹ve got to uncheck the Create sort
    > descriptors
    > binding option for each column value binding.

    No, it *is* true. Try it, and you will see that you are completely wrong
    about this point. At least for Tiger and lower, but I would expect it to
    work the same on Leopard. I did forget to mention a step: you have to bind
    both "content" and "selectionIndexes" to the array controller. This way you
    override the implicit bindings set when you bind the table column value. So,
    unless you bind sortdescriptors, the tableview won't effect sorting.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
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