Re: Sorting NSTableView
Re: Sorting NSTableView
- Subject: Re: Sorting NSTableView
- From: "Joe Goh" <email@hidden>
- Date: Wed, 23 Aug 2006 21:08:56 +0800
On Jun 22, 2006, at 5:18 AM, Alexander Lamb wrote:
I have a core data application.
I would like to force the sort on a given column when the data is
loaded in my NSArrayController and displayed in the NSTableView.
Sorting works fine manually (e.g. when clicking on the column
header) so I would like to do as if the used had clicked.
I know I can sort programmatically the objects in my controller,
but I want to show the visual feedback of my column with the little
sort triangle.
I am now facing the exact same problem as Alexander did, and after
trying the solution suggested to him and many others posted on various
blogs/forums for the past six hours, I still can't get it working.
:-(
Here's the solution given to Alexander,
On Jun 22, 2006, at 11:20 AM, George Orthwein wrote:
Ah, it's actually setSortDescriptors you want. Set it in
windowControllerDidLoadNib:
NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc]
initWithKey: @"displayOrder" ascending: YES] autorelease];
[tableView setSortDescriptors:[NSArray
arrayWithObject:sortDescriptor]];
I placed the following code in the awakeFromNib method for the
NSTableView subclass (ContactView), as i'm not writing a
document-based app:
@implementation ContactView
- (void) awakeFromNib
{
NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc]
initWithKey: @"name" ascending: YES] autorelease];
[self setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[self reloadData]; // Is this needed?
}
@end
I have only one column in my NSTableView, and using bindings/Core
Data, the "name" attribute is now successfully being shown in the
view, and it can be sorted when I click on the header, but not when
the application first starts.
Is "name" the correct argument to use as a key for NSSortDescriptor's
initWithKey? Any other clues as to why the column is still not being
sorted by default when the application starts?
Thanks in advance,
Joe
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden