I have a an NSTableView when ever I click on a specific header column the data in the table get reversed or sort upside down. I have checked NSTableView
as well as NSTableColumn
but couldn't find any method that disables this. I would be obliged if anyone can help in disabling this sorting on clicking on the header of a particular column.
Asked
Active
Viewed 4,058 times
9

dmckee --- ex-moderator kitten
- 98,632
- 24
- 142
- 234

Omayr
- 1,949
- 4
- 22
- 35
-
1Damn, please don't prefix your question title with "[Objective C]". Not only are you missing a hyphen, but you are also missing the point. That's what tags are for. – Jonathan Sterling Nov 30 '10 at 07:10
-
@ Jonathan: I would have appreciated, had you come up with some answer – Omayr Nov 30 '10 at 07:50
-
1Do you use Cocoa Bindings? What are your settings? – Yuji Nov 30 '10 at 08:05
-
@Yuji bindings, what for I think it has to do with the GUI i have an NSArrayController bound to it but I guess a GUI function has nothing to do with this . – Omayr Nov 30 '10 at 08:12
-
1Well, it has lots to do with this ... :p Binding is too magical, you know. Before the days of bindings, the `NSTableView` didn't magically sort itself; we needed to implement it ourselves. – Yuji Nov 30 '10 at 08:14
-
@Yuji, sorry buddy I underestimated your guess. You were right binding is really magical. Anyway thanks ! – Omayr Nov 30 '10 at 09:38
1 Answers
37
Sorting of the NSTableView
is done by its sortDescriptors
, see here.
An NSTableColumn
uses its sortDescriptorPrototype
(see here) to generate the sort descriptor of the NSTableView
, depending on how many times you clicked the column header, etc.
If you use dataSource
to manage the data, then the sort descriptor is communicated via the delegate method tableView:sortDescriptorsDidChange:
, see here. You just need to ignore the change message to stop sorting.
If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController
. To stop it, just open the inspector of the binding of the table column, select value
, and uncheck "Creates Sort Descriptor."

Yuji
- 34,103
- 3
- 70
- 88
-
Walaah ! that was awesome, I was using bindings and the problem is solved now. Thanks alot buddy – Omayr Nov 30 '10 at 09:36
-
thanks! how can `To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor."` be done programmatically?? – sharkyenergy Mar 02 '13 at 12:13
-
You can create a property which always returns the same array of sort descriptors and bind the `NSTableView` to this property. – Flovdis Mar 12 '14 at 15:02
-
> If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController. To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor." ......... I don't see this option on Xcode 8.x – Duck Feb 08 '17 at 14:46
-
“You just need to ignore the change message to stop sorting” makes no sense. It's a delegate method, you implement it, how do you *ignore* it? Code example would have helped. -1. – mxcl Apr 09 '18 at 00:57
-
@mxcl You just implement a delegate method which does nothing. It's no different from how to deal with your annoying neighbor who asks you to do many things: you reply "I'll do something" and actually does nothing :-) – Yuji Apr 10 '18 at 02:07