How to get NSFormatter subclass to work with NSTableColumn sort key and selector?
- by Andrew
My setup:
I have a sqlite database from which I populate a NSMutableArray of NSDictionary objects this is the DataSource for my NSTableView.
One of the columns holds "time", the time is a float that holds seconds.
I would like to display the values in this column as minutes:seconds. For instance my data would be 123.4329387 I want to display 2:03 which I have no problem doing with a subclass of NSFormatter (or NSNumberFormatter) applied to my NSTextField in the column.
I have sorting set up by using the Table Column Attributes in IB, I just have the sort key set to "time" and the selector set to "compare:" which works fine without the formatter.
Currently this gives me something like this when I sort (descending)
1:37, 1:31, 0:10, 0:10, 0:09, 1:30, 1:30, 1:26, 0:09
and similar nonsense, it looks like something is going on but it's definitely not sorted.
How do I get the sort to look at the underlying data instead of the formatted value? Alternately, how do I specify a custom sort method and where do I put the code for said method? I have searched around quite a bit and have not found anything to help me out with this problem, any help with this is most appreciated.