Sorting of table column by string length not working as intended when done in IB via

Discussion in 'Mac Programming' started by Monaj, Jun 13, 2010.

  1. Monaj macrumors regular

    Joined:
    May 24, 2009
    #1
    Hi all,

    I made a sample application displaying list of employees with their salaries over NSTableView using NSArrayController.

    Basic functionality is working as intended. Also sorting is working fine when Selector - "compare" or "caseInsensitiveCompare" is assigned in attribute pane for table column- "employeeName".

    Problem occurs when I try to sort it by string length by setting selector in IB as - "length", for the table column - "employeeName". It does sorting by string length but does it inappropriately.

    It is doing sorting on alternate clicks ie. on first click it sorts the content in table in descending order by length. Then on second click it does not arrange contents in ascending order by length but sets arrow on top as in ascending. Then on third click it arranges contents in ascending order by length but sets arrow on top of table column as in descending and so on...

    Can anyone suggest if I am wrong somewhere?

    Thanks,

    Monaj
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    Odd that that would work. The comparator method should have an argument, -compare: does, -length does not. Look in your console to see if there are any error messages, inconsistent behavior often shows up there.

    You might also note that -compare: returns an enumerated type (number) that is normally -1 (NSOrderedAscending), 0 (NSOrderedSame) or 1 (NSOrderedDescending), so the sorting operation is likely always seeing the result as NSOrderedDescending. This could lead to confusion if you use it alone as a conditional argument as the result will be false when the receiver and the argument are equal.
     

Share This Page