• 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: Sorting NSTableView using Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting NSTableView using Bindings


  • Subject: Re: Sorting NSTableView using Bindings
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 05 Nov 2012 19:35:43 -0600

On Nov 5, 2012, at 12:50 PM, Quincey Morris wrote:

> On Nov 5, 2012, at 10:03 , Paul Johnson <email@hidden> wrote:
>
>> I can sort the table by clicking on column headers, but when the
>> drawer is opened the data is unsorted.
>
> Yes, because clicking on column headers causes the table view to *create* the array of sort descriptors.
>
> What you need to do is create a property in your data model that holds the sort descriptors. Bind the array controller's Sort Descriptors binding to this property. That causes the array controller's arrangedObjects to be ordered according to the sort order in the data model property, and the table view gets this order (via arrangedObjects) without additional work.
>
> If the column header is clicked, the table view updates its own sortDescriptors property, which (via its automatically configured binding) updates the array controller's sortDescriptors property, which (via its manually configured binding) updates the data model property.
>
> Chances are you'll also want the data model property to updates user defaults when set, and initially load its value from user defaults on startup.

That's all fine and good but maybe more than needed.

If you're just looking for a quick and simple fix, you can set up an outlet from your window controller to the array controller -- there's a good chance you already have that -- and, during -awakeFromNib or -windowDidLoad, simply set the array controller's sortDescriptors property.  That will set the initial sort order.  Clicks in table column headers will change that property as necessary.

Cheers,
Ken


_______________________________________________

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

References: 
 >Sorting NSTableView using Bindings (From: Paul Johnson <email@hidden>)
 >Re: Sorting NSTableView using Bindings (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Harnessing Perl Scripts within a Project
  • Next by Date: Re: Extremely low fps during transparent NSWindow resize
  • Previous by thread: Re: Sorting NSTableView using Bindings
  • Next by thread: Re: Sorting NSTableView using Bindings
  • Index(es):
    • Date
    • Thread