initial sort of NSTableview

I have a tableview with data coming from the web. I load this data, I display my tableview and everything is good except one little thing;

the initial sort position is not refledted in the corresponding column header


If I click on a column after the table is loaded, the sort is done and the header of the column has the symbol of a sorted column

But when the table is initially loaded, no symbol appears


of course, I tried to put some instructions like:

let descriptorName = NSSortDescriptor(key: "nomlocataire", ascending: true)

tablesaisie.tableColumns[1].sortDescriptorPrototype = descriptorName


but no symbol appears on the corresponding header column

What did I missed?

Replies

According to the documentation:


https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/SortingTableViews/SortingTableViews.html


setting the table column's "sortDescriptorPrototype" property doesn't tell the table view that the data is sorted on that column. It just tells the table view what sort descriptor to use when the user clicks on that column header.


To get the result you want, it looks like you also need to set the table view's "sortDescriptors" to an array whose first element is the column's sort descriptor. Unfortunately, the documentation isn't very clear on this point, so you may have to experiment a bit, to get your code to do what manually clicking on the column header does.