Re: sorting with nstreecontroller
Re: sorting with nstreecontroller
- Subject: Re: sorting with nstreecontroller
- From: Philip Dow <email@hidden>
- Date: Thu, 5 Jan 2006 09:27:15 +0100
Hi David,
What kind of objects are being added to the controller? If you can
add another property to the object, something like "type," you could
have the controller sort according to type first and then
categoryName. Your default category type could be 1 and all the
others 2 or something like that.
First, build an array of sort descriptors:
mySortArray = [[NSArray alloc] initWithObjects:
[[[NSSortDescriptor alloc] initWithKey:@"type" ascending:YES
selector:@selector(compare:)] autorelease],
[[[NSSortDescriptor alloc] initWithKey:@"categoryName" ascending:YES
selector:@selector(caseInsensitiveCompare:)] autorelease], nil];
Then have the controller sort according to that array:
[myTreeController setSortDescriptors:mySortArray];
Make sure your type property is kvo compliant and don't forget to
release the array when finished!
-Phil
On Jan 5, 2006, at 8:03 AM, David Chan wrote:
Hi all,
I have an NSOutlineView that is using NSTreeController. It only
displays one field, categoryName.
Now it seems that the field is automatically sort-able alphabetically.
But there is one so-called "default category" which I would like to
always keep on top of the NSOutlineView while the other categoryNames
get sorted. How can I get this done? Thanks a lot.
Regards
David
_______________________________________________
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
_______________________________________________
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