Re: Sorting a bound NSTableView programatically
Re: Sorting a bound NSTableView programatically
- Subject: Re: Sorting a bound NSTableView programatically
- From: Jean-Nicolas Jolivet <email@hidden>
- Date: Wed, 17 Dec 2008 23:26:36 -0500
Thanks to both of you for the advices!
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.
This made sense hehe not sure why I didn't think of it... basically I
decided to load the data in my model, sort my NSMutableArray and then
fire didChangeValueForKey:myMutableArray....to update the
ArrayController's content..
this way my mutable array is sorted too... and I just disabled re-
ordering in IB on the table....
Jean-Nicolas Jolivet
email@hidden
http://www.silverscripting.com
On 17-Dec-08, at 10:44 PM, Ken Thomases wrote:
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