Sorting a Table View Programmatically

I wont to sort a table view by a date column (“dasDatum”).
I know I can do it by clicking the header cell and using tableView_sortDescriptorsDidChange_.
But the table starts without sorting and new data are added at the end of the table. To avoid it I’m looking for a programmatically solution.
My attempts are leading to nowhere.
To add new data for example:


property SortDescriptorClass: class "NSSortDescriptor"
property NSArrayClass: class "NSArray"

set NewData to {derTermin:derTermin, derKalender:derKalender,dasDatum:dasDatum}
tDataSource's addObject_(NewData)

set theDescriptor to SortDescriptorClass's sortDescriptorWithKey_ascending_("dasDatum",true)
log theDescriptor -- (dasDatum, ascending, compare:)
tTableView's setSortDescriptors_(NSArrayClass's arrayWithObjects_(theDescriptor,missing value))

tTableView's reloadData()

No error message.
What is wrong?

Heiner

Hi,

it should be sufficient to sort the dataSource array

property SortDescriptorClass: class "NSSortDescriptor"
property NSArrayClass: class "NSArray"

set NewData to {derTermin:derTermin, derKalender:derKalender,dasDatum:dasDatum}
tDataSource's addObject_(NewData)

set theDescriptor to SortDescriptorClass's sortDescriptorWithKey_ascending_("dasDatum",true)
log theDescriptor -- (dasDatum, ascending, compare:)
tDataSource's sortUsingDescriptors_(NSArrayClass's arrayWithObject_(theDescriptor))

tTableView's reloadData()

Thank you Stefan and I’m a little bit ashamed.

Heiner

Ja ja, der Wald und die Bäume. (engl. the wood and the trees)

You can also simplify it a bit and let the bridge make the array:

tDataSource's sortUsingDescriptors_({theDescriptor})