I've got a cocoa app that's got a TableView with bindings to a model through an NSArrayController.
The app works as I want, but the default sort order of the table is wrong.
I typically start the program and click on the last header twice to get it sorting the right way. Is there a way in the nib/bindings/whatever to specify the default sort order, or to programatically tell it to do what would happen if I clicked there twice? Or even just remember the previous sort order?
-
Look at NSSortDescriptor.
You can set it up using -setSortDescriptors: on the NSTableView. Or you can put the sort descriptors in an ivar and bind them with the Sort Descriptor binding in IB.
-
I typically do this sort of thing in -awakeFromNib. Suppose your NSWindowController subclass has the IBOutlet _arrayController set to the NSArrayController in question, and that your model possesses the property buildETA:
NSSortDescriptor *buildETASortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"buildETA" ascending:NO]; [_arrayController setSortDescriptors:[NSArray arrayWithObject:buildETASortDescriptor]]; [buildETASortDescriptor release];Dustin : This doesn't seem to update the view to indicate that it's sorted that way. -
Today (seemingly by coincidence), Simone Manganelli published a blog post with the solution.
0 comments:
Post a Comment