Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to Sort an NSTableView with Bindings?

How to Sort an NSTableView with Bindings?
Thread Tools
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jan 17, 2005, 06:10 AM
 
I've been raking through documentation, forums and Google for days now, with no luck. I can't figure out how bindings are supposed to make sorting work easily. All the information I've read indicates that it just happens automatically, but doesn't actually say how to make it happen automatically.

I cannot make my table sort under any circumstances, either by clicking on a table column, or use a default sort order. I'd be interested in finding how to do both, but what I really need at the moment, is for the table to stay sorted, no matter what happens, without the user ever clicking on a column header.

Currently I've got the NSTableView bound to an NSArrayController, and each of the NSTableColumns bound to the same NSArrayController. The table view's bindings include content, selectedIndexes and sortDescriptors.

What else do I need to do?

You may need to go back to first principals for me, because I get the feeling I'm missing some very basic concept(s) here, as all the documentation appears to be assuming that it's a lot easier than I'm making it out to be.

Any help is greatly appreciated.
     
ntt
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Seattle, WA
Status: Offline
Reply With Quote
Jan 17, 2005, 11:01 AM
 
Originally posted by Brass:
Currently I've got the NSTableView bound to an NSArrayController, and each of the NSTableColumns bound to the same NSArrayController. The table view's bindings include content, selectedIndexes and sortDescriptors.
I'm relatively new to cocoa-bindings, and I've been approaching it from a cocoa-java perspective (which is woefully limited, sadly). I have managed to get an NSTableView sorting when clicking on columns using bindings. It was automatic.

What was different in my situation was that I had the various columns of the NSTableView bound to properties of the objects that were contained in the NSArray. In otherwords, I had a class called UpdateWrapper that contained an NSMutableDictionary that defined key-value 'properties' of the object, and I named the NSMutableDictionary 'properties'.

Then I bound each column in the NSTableView to the NSArrayController's 'arrangedObjects' controller key... with the model key path set to 'properties.name', for example.

Once the bindings were working the sorting functionality was free.

Hope that helps. I learned a lot of what I know from here:
http://www.cocoadevcentral.com/articles/000080.php
http://bestbits.ii.net/ for widgets and more
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:59 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,