Women in Technology

Hear us Roar



Article:
  Mac OS X's Preferences System (and More!)
Subject:   Sorting?
Date:   2001-09-14 22:20:55
From:   n9yty

I've been trying to figure out (with no luck) how to get the tableView to sort....


I looked around and found a reference in setDoubleAction:(SEL) to set a selector used when a column header is double clicked... But how do I tie that to my code?


Further, I see clickedColumn in tableView, but it returns an index... Since you can re-arrange the columns, how do you know which one is which at runtime? I thought about something like using tableColumns to get the columns, then objectAtIndex:colnum to get the column clicked in, and finally the identifier method of this to get the column name.


Is this the wrong path? Any insight, please? :-)


Thanks for a great series of articles. I gave up most of my C programming back when I switched from my Amiga (Intuition was a nice environ for it's time, IMHO) to Windows (VisualBasic, but let's not go there...), and since moving to the Mac I've never gotten into programming, but Cocoa and MacOS X are really intriguing me... Most of my day-to-day work is in Perl/Shell/SQL/C for various Unix "back-end" things.

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • Sorting?
    2001-09-15 06:08:57  n9yty [View]


    Oh, forgot something...

    I figured that once I had the identifier tag for the clicked-column, I could simply call the records sortUsingFunction, with a function that uses caseInsensitiveCompare on the values in the given column, which will be plucked out by the identifier name, passed into the function via the context: parameter.

    [records sortUsingFunction:stringSort context:identifier]

    and stringSort is basically something like:

    NSString *v1 = [val1 objectForKey:context];
    NSString *v2 = [val2 objectForKey:context];

    return [v1 caseInsensitiveCompare:v2];

    Is this really off track?

    Thanks again!

    • Sorting - Sorting it out...
      2001-09-15 20:21:36  n9yty [View]


      Okay, found my problem with using the doubleAction to set the selector, I didn't know I had to setTarget first... Got that done, and now everything else has fallen into place and it seems to work great.... Hmm... Instead of sorting based on column clicked on, though, I'm wondering about a sort button that sorts based on the order you have columns positioned? Food for thought, but it's working as-is for now.
      • HELP!!!
        2002-02-08 02:40:53  stupidfish23 [View]

        Hi there! Could anyone post a working source code that makes the table sort its records? I just can't get it to work...

        Please?

        Email me at: stupidfish23@mac.com