0

I'm binding an NSTableView to an NSArrayController. For some reason, I can't sort the columns at all. Some columns don't even show the sort direction arrow. Some do show it, but clicking it just toggles the arrow direction, it doesn't actually sort the content at all.

This is all in IB so there's no code to show.

Auto Rearrange Content is checked on the NSArrayController.

The table view Table Content section is bound, and that works. There's a Sort Descriptors area under the table view bindings, but I don't know what to set that to. I tried binding it to the same array controller and setting the Controller Key to arrangedObjects but that causes a crash at runtime. (It's trying to send the "key" selector apparently.)

EDIT: here is a sample project that illustrates the problem. The table headers show the sort direction arrows but the table data does not change when you click the header. https://www.dropbox.com/s/yhvpxo9b73vj9it/bindingtest.zip

jsd
  • 7,673
  • 5
  • 27
  • 47

1 Answers1

1

Under the attributes inspector, you need to provide the sort key and the selector (compare:). This will start sorting the table columns and you need to set this for each table column.

Also, for your reference you can get my sample code from: Project

Once the app is launched, you can click load drawer and load table and then click the header to sort the column. In this example I have set the sort key same as the value binding key.

I hope this helps.

  • Your sample app doesn't work. It throws an exception when you try to sort the column (FruitModel compare: unrecognized selector). – jsd Apr 04 '14 at 04:00
  • I hope you havent modified anything in the code. It works fine and regarding compare:, its a standard sort method. It works for me! – Aneesh Dangayach Apr 04 '14 at 05:52
  • I don't know what to tell you. I didn't modify it. OSX 10.9.2, Xcode 5.1. Here's the console output when clicking the table header: http://pastebin.com/Mmfm38wL – jsd Apr 04 '14 at 14:13
  • Since you are having a problem in sorting, I will suggest to create a test project which is simple and concentrated on sorting the table column – Aneesh Dangayach Apr 04 '14 at 18:11
  • 2
    I saw your code and was able to sort the columns by removing one binding. In IB, Window->View->Bordered Scroll View->Clip View-> Table View. On this tableView there is a binding for Table Content, remove this binding because it is not required and try. It works ! – Aneesh Dangayach Apr 04 '14 at 23:25
  • Can't believe it was something so stupid! All good now. Thanks man! – jsd Apr 05 '14 at 03:23
  • @jsd Have you removed the project from Dropbox? (the link is dead) I was looking forward to studying your setup. – David Mar 28 '15 at 17:54