Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.