Re: Sorting a bound NSTableView programatically
Re: Sorting a bound NSTableView programatically
- Subject: Re: Sorting a bound NSTableView programatically
- From: Ken Thomases <email@hidden>
- Date: Wed, 17 Dec 2008 21:44:51 -0600
On Dec 17, 2008, at 8:53 PM, Jean-Nicolas Jolivet wrote:
What I need to do then, is to sort my tableview by FirstName
automatically and then disable sorting altogether....
When you bind the columns of a table, there's an implicit binding of
three bindings on the table itself: content, selectionIndexes, and
sortDescriptors. Those implicit bindings are only set up, though, if
the table has no explicit bindings for any of those three.
So, to disable sorting of a table, you bind its content to the array
controller's arrangedObjects and bind its selectionIndexes to the
array controller's selectionIndexes, and leave the table's
sortDescriptors unbound.
To achieve the original sort, you can do a few things. You can bind
the array controller's sortDescriptors binding to a property on your
coordinating controller which returns an array of sort descriptors.
This array will be constant, since you only want to allow the one sort
order.
Alternatively, you can call setSortDescriptors: on the array
controller in code to achieve the same result without a binding.
Lastly, you can treat the ordering not as a view property but as a
model property. You would sort the array in your model, probably just
after reading it in.
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