Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top