In article <chello.com>,
C Lund <no> wrote:
If you're not in 10.3, you have to do the sorting yourself. I have some
code that does exactly what you need, though. :)
First, override tableView:shouldSelectTableColumn: in your delegate.
Columns are selected when the user clicks in the header, so that's how I
get the clicks. There's probably another, maybe better way to do this,
but that's how I do it. Then what I do is get the identifier of the
table column, and that tells me how things should be sorted. If the
identifier is the same as the previous identifier, then that's my signal
to flip from ascending to descending order. Then do this:
[tableView setIndicatorImage:nil inTableColumn:oldColumn]
(Substitute Descending when appropriate.) This sets the little triangle
thing, and removes it from the old column.
That takes care of the interface question. Then you have to actually
sort your data. I have an update method that re-does all of my data,
which includes sorting, and then tells the table view to reload its
data. My list is a single array of objects, where each columns uses a
different selector to get information from those objects. My sort
function uses NSMutableArray's sortUsingFunction:context: to sort that
array using the same selectors that are used to get the table columns.
(I hope that's all suitably unclear....)
From what I understand, this is all very easy to accomplish using
NSArrayController and NSSortDescriptor in 10.3, but I have no idea how
they work. As I recall, you're using some ancient version of OS X, in
which case you can't use them anyway.