Re: Table sort image question
Re: Table sort image question
- Subject: Re: Table sort image question
- From: Andy Lee <email@hidden>
- Date: Tue, 06 Jan 2009 14:30:36 -0500
On Jan 6, 2009, at 2:18 PM, Jon C. Munson II wrote:
OK, I looked into the method:
- (void) tableView:(NSTableView*) aTableView
sortDescriptorsDidChange:
(NSArray*) oldDescriptors
And decided to give it a shot after much play with the prior
method. In
that prior method I found that the sortDescriptors and Prototype
were not
getting changed as expected, thus my use of those items wasn't valid.
Certain values in the descriptors weren't changing as expected.
So, I created a subclass of NSTableView to implement the method above.
I found that sortDescriptorsDidChange is not getting called.
You are supposed to implement the above method in the table view's
*data source*.
<http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html
>
The full name of the method is tableView:sortDescriptorsDidChange:.
It takes two arguments, the first being the table view whose sort
descriptors changed.
--Andy
I am not able to find any further reference to implementation of
that method
to make sure I implemented it correctly.
My subclass isn't complicated, essentially containing a pointer to
the view
which needs to stay in sync with the table (so I can call a method
to update
the sortDescriptors for the underlying data), and the method above.
Did I miss something? Based on what I see, I think the
sortDescriptors
aren't even being used when the column sort happens...or is that wrong
thinking?
Thanks in advance!
Peace, Love, and Light,
/s/ Jon C. Munson II
-----Original Message-----
From: Jon C. Munson II [mailto:email@hidden]
Sent: Tuesday, January 06, 2009 10:09 AM
To: 'Graham Cox'
Cc: 'cocoa dev'
Subject: RE: Table sort image question
On 7 Jan 2009, at 12:18 am, Jon C. Munson II wrote:
1. When is didClickTableColumn actually called? Is it after the
table does
its stuff, including setting the sort descriptors, or just prior to
that?
This is not the method you want. You want the NSTableDataSource
method:
- (void) tableView:(NSTableView*) aTableView
sortDescriptorsDidChange:
(NSArray*) oldDescriptors
In this method, you can retrieve the *current* sortDescriptors from
the tableview, and sort a mutable array using:
- (void) sortUsingDescriptors:(NSArray*) sortDescriptors
[Jon C. Munson II] Thank you for this, I'm looking into it now.
Note that the sort descriptors passed in the first method are the old
ones, not the current ones, so you have to go back to the table to get
the new ones. Having sorted the array, you need to reload the table to
display the outcome. That's all - there's nothing else you need to do
to support sorting from table columns except setting up the sort key
and selector in IB.
[Jon C. Munson II] OK. Thank you for that. I decided to stick with
the
delegate method of didClickTableColumn as it functionally provides
the same
thing (at this time) without having to create yet another class,
instantation, etc. I will keep that in mind for future use though,
so I
appreciate the pointer to it.
2. In attempting to answer #1, I ran into an issue with using the
-ascending message. The doc states its returns a bool, however, I
could not
use the message. Any ideas there?
I don't see any reason to actually try and access the sort descriptor
itself - just use it as a black box. Note that sort descriptors come
in an array, so there could be several, one for each sortable column.
I can't see immediately in the docs what order they come in, so you
can't necessarily tell which sort descriptor represents a particular
column (though my *guess* is that the first one is the selected column
header).
[Jon C. Munson II] I found in subsequent testing that
didClickTableColumn
appears to get called after the table sets its sort descriptors,
etc. So,
as you pointed out, I didn't need to do anything really with the sort
descriptor other than "pass it along." Now, I've got to unhook the
sortKeys
in my hack of covertflow and use the sort descriptor as passed.
Adapt and
overcome....
Thank you for your help so far.
_______________________________________________
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