• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableView: programatically changing sorted column
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView: programatically changing sorted column


  • Subject: Re: NSTableView: programatically changing sorted column
  • From: Scott Anguish <email@hidden>
  • Date: Mon, 5 Jul 2010 23:15:14 -0400

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@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

  • Follow-Ups:
    • Re: NSTableView: programatically changing sorted column
      • From: Graham Cox <email@hidden>
References: 
 >NSTableView: programatically changing sorted column (From: Graham Cox <email@hidden>)
 >Re: NSTableView: programatically changing sorted column (From: Kyle Sluder <email@hidden>)
 >Re: NSTableView: programatically changing sorted column (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Custom bundle icon
  • Next by Date: Re: NSTableView: programatically changing sorted column
  • Previous by thread: Re: NSTableView: programatically changing sorted column
  • Next by thread: Re: NSTableView: programatically changing sorted column
  • Index(es):
    • Date
    • Thread