Re: Sorting a bound NSTableView programatically
Re: Sorting a bound NSTableView programatically
- Subject: Re: Sorting a bound NSTableView programatically
- From: Kiel Gillard <email@hidden>
- Date: Thu, 18 Dec 2008 14:17:37 +1100
Have you tired [arrayController rearrangeObjects]? <http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSArrayController_Class/Reference/Reference.html#//apple_ref/occ/instm/NSArrayController/rearrangeObjects
>
You may need to ensure that the sort descriptors of the table view are
bound to the NSArrayController instance.
Finally, there is a boolean attribute of NSArrayController in IB's
Attributes Inspector labelled "Auto Rearrange Content". Ticking this
should keep your model objects sorted as well.
Hope this helps,
Kiel
On 18/12/2008, at 1:53 PM, Jean-Nicolas Jolivet wrote:
I'm pretty sure this one is obvious but I'm just spinning around in
circles in the docs here and I can't seem to find out how to do it...
I have a basic NSTableView binding setup in place (NSTableView's
columns bound to an NSArrayController, which is bound to an
NSMutableArray ...)
I'm trying to keep things simple so lets say my NSMutableArray is
filled with custom "Person" objects that have only 2 properties:
FirstName and LastName (the 2 columns of my NSTableView)...
Now, without doing anything (basically, just by setting my bindings
correctly in IB) I can sort the 2 columns (FirstName and LastName)
by clicking their headers, it works just fine (I'm guessing because
"Create Sort Descriptors" is checked in IB)...
Now the thing is, the NSMutableArray is populated by an XML file
that I am opening and parsing (again, no problems with that part)...
I parse the XML file, which contains First names and Lastnames,
create and add my "Person" objects to my array and the data is added
to my NSTableView automatically....
What I need to do then, is to sort my tableview by FirstName
automatically and then disable sorting altogether....
Basically, I am only opening XML files, the user is not allowed to
add new rows/remove rows/etc. in the table, I only want to show the
data, ordered alphabetically ....
Now I think I can "disable" sorting by unchecking "Create Sort
Descriptors" in IB for my 2 columns, but I can't figure out how to
sort my table view programatically...
(Also, while I'm on the subject, does sorting the
NSArrayController's arrangedObjects also sorts the NSMutableArray to
which my NSArrayController is bound to??)
Thanks,
Jean-Nicolas Jolivet
email@hidden
http://www.silverscripting.com
_______________________________________________
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
_______________________________________________
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