Cocoa – How to set a default sort order for an NSTableView


I've got a cocoa app that's got a TableView with bindings to a model through an NSArrayController.

The app works as I want, but the default sort order of the table is wrong.


I typically start the program and click on the last header twice to get it sorting the right way. Is there a way in the nib/bindings/whatever to specify the default sort order, or to programatically tell it to do what would happen if I clicked there twice? Or even just remember the previous sort order?

Best Solution

Look at NSSortDescriptor.

You can set it up using -setSortDescriptors: on the NSTableView. Or you can put the sort descriptors in an ivar and bind them with the Sort Descriptor binding in IB.