Sorting a view based TableView with bindings

  • I have a cell-based TableView which is filled via ArrayController using bindings.
    Sorting just works.

    Now I changed this to a view-based TableView and suddenly no more automatic sorting.
    It has just one column which uses an NSTableCellView.
    The Static Text has it's Value bound to Table Cell View objectValue.Name.

    And I want the column to be sorted via localizedCaseInsensitiveCompare:.

    I tried to set in “Table Column Attributes inspector”:
    Sort Key = objectValue.Name or Name
    Selector = localizedCaseInsensitiveCompare (with trailing : or not)
    The values seems to be irrelevant; anything non-nil activates the up/down triangle. But nothing changes the order of the rows.

    When I click on the header nothing happens (except the current selection is set to none and the small triangle on the right side alternate between up and down).

    What am I missing? What documentation should I read?

    Gerriet.
  • On May 2, 2013, at 00:31 , "Gerriet M. Denkmann" <gerriet...> wrote:

    > When I click on the header nothing happens (except the current selection is set to none and the small triangle on the right side alternate between up and down).

    At a wild guess, I'd suspect you neglected to bind the table's Sort Descriptors binding to the array controller's "sortDescriptors" property. This probably happens automatically for a cell-based table view, but perhaps (like the Content binding) needs to be done explicitly for a view-based table view.

    > What am I missing?

    Possibly that using bindings with a view-based table view is more trouble than it's worth? (I don't mean bindings to the cell view's objectValue. That's worth doing.) But I digress…
  • On 2 May 2013, at 14:49, Quincey Morris <quinceymorris...> wrote:

    > On May 2, 2013, at 00:31 , "Gerriet M. Denkmann" <gerriet...> wrote:
    >
    >> When I click on the header nothing happens (except the current selection is set to none and the small triangle on the right side alternate between up and down).
    >
    > At a wild guess, I'd suspect you neglected to bind the table's Sort Descriptors binding to the array controller's "sortDescriptors" property. This probably happens automatically for a cell-based table view, but perhaps (like the Content binding) needs to be done explicitly for a view-based table view.

    You are correct. I added this binding.
    And I also set the TableColumn to:
    Sort Key = Name
    Selector = localizedCaseInsensitiveCompare:

    Both seem to be necessary.

    >
    >> What am I missing?
    >
    > Possibly that using bindings with a view-based table view is more trouble than it's worth? (I don't mean bindings to the cell view's objectValue. That's worth doing.) But I digress…

    My experience with TableViews is: I usually start with bindings, but when things start getting a bit more complicated (they usually do) I switch back to DataSource. Slightly more code, much less head-ache.

    But this project is just about learning.

    Thanks for your help!

    Kind regards,

    Gerriet.
previous month may 2013 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