are you implementing the delegate method?

- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray 
*)oldDescriptors
{
        // the sort descriptors are specified in Interface Builder for the 
lastName column and the relationship column
        // the both specify the respective keys, and use the compare: method to 
do the sorting
        // this message is sent to the delegate when the data is sorted by 
clicking on one of those column headers
        [peopleArray sortUsingDescriptors: [tableView sortDescriptors]];
    [tableView reloadData];
}


I’m setting the sort information in Interface Builder on each column, 
specifying the key to sort on, and the compare selector (which is compare: 
which probably isn’t the best for localized content). I agree that both the 
hidden and non-hidden columns should have the same key and compare selector for 
both columns.

When you click on one of those table column headers, the delegate is notified.

Now, this does ‘destroy’ the natural sort order. But you can easily copy that 
natural order array into a ‘displayed’ array when loaded, and then upon some 
action, put a copy of that natural array in the displayed array. The delegate 
implementation above would do something like 

self.displayArray=[naturalOrderArray sortedArrayUsingDescriptors:[tableview 
sortDescriptors]];

Is this helpful? If you’re having sorted issues that need documenting file a 
bug and send me the number ASAP. Seriously, ASAP.


On Jul 5, 2010, at 10:36 PM, Graham Cox wrote:

> I'd still like to know how a programmatic change to sort descriptors in a 
> table view ought to be accomplished. It seems that the "highlighted" column 
> really has logically nothing to do with the table's sort descriptors, even 
> though when you interact with a table that's exactly what is used to indicate 
> the sorted column. Weird.

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to