Re: Removing sorting from NSTableView
Re: Removing sorting from NSTableView
- Subject: Re: Removing sorting from NSTableView
- From: Graham Cox <email@hidden>
- Date: Mon, 19 Jul 2010 15:56:33 +1000
On 19/07/2010, at 3:12 PM, Scott Anguish wrote:
>
> On Jul 18, 2010, at 8:03 PM, Graham Cox wrote:
>> There's not really any such thing as an "unsorted" order.
>>
>
> I’d disagree. Perhaps in Core Data. But in the case of arrays there can be a natural order.
That's not unsorted, it's a natural order. Unsorted to my mind is what you get from a set. If it's an array, it can never be unsorted (though for sure there may be no intended meaning to the order). If this natural order matters, something has to either keep it in that order or else has some information to allow it to be restored to this order.
>> but as I found the other week it's probably better to move the sort descriptor handling to your controller (tableview's datasource/delegate) and take that responsibility away from the tableview.
>
> If you can tell me why (off-list) that might be very useful to some doc.
Briefly, the upshot of this thread: http://www.cocoabuilder.com/archive/cocoa/290204-nstableview-programatically-changing-sorted-column.html#290204 was that using NSTableView to manage something that really belonged in my controller made hard work of it.
In that case it was because the table view was only one possible view of the data - I also have an icon view using a wholly custom view class, but which shares the sorting order with the table view. If you only have a table view then leaving it to manage the sort descriptors is fine provided you don't want to do anything out of the ordinary with them. But Gideon does want to do something out of the ordinary - he wants to get back to the natural order of his data without displaying it in a column (I assume) which a standard table view doesn't support. As soon as he needs to manipulate the list of sort descriptors externally it might be easier to do in the controller. (Though I guess if there is an array with the original 'natural' order then it could be a case of removing all the sort descriptors altogether from the table and using the existence of this empty array to flag* that the natural order should be returned - but getting the table view to include this state appears to require a custom header at least, as you suggested).
*Might require no code - if [NSArray sortedArrayUsingDescriptors:<the empty array>] returns the original array unchanged, which seems like the logical thing to do though the docs don't say so explicitly.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden