Re: 'Static' items in an NSOutlineView
Re: 'Static' items in an NSOutlineView
- Subject: Re: 'Static' items in an NSOutlineView
- From: Ernesto Giannotta <email@hidden>
- Date: Sun, 23 Oct 2011 13:22:30 +0200
On 18-ott-2011, at 04:58, Koen van der Drift wrote:
> As I posted a few days ago, I was able to create the 'static items' in my outlineview,
>
> What I am now trying to do is to set the order of the static items, without changing the order of the other groups in the view. Using a sortdescriptor won't work, since it will order *all* groups, including the static ones.
>
A subclass of NSSortdescriptor will fit the job.
Taken from my own project, but should render the idea:
- (NSComparisonResult)compareObject:(id)object1 toObject:(id)object2
{
//NSLog(@"custom sort called");
// cast proper objects
NSMutableDictionary *categoryItem1 = object1;
NSMutableDictionary *categoryItem2 = object2;
NSNumber *categoryID1 = [categoryItem1 valueForKey:@"categoryID"];
NSNumber *categoryID2 = [categoryItem2 valueForKey:@"categoryID"];
if ([categoryID1 intValue] == 0) {
// represents all notes, always first item
return NSOrderedAscending;
}
if ([categoryID2 intValue] == 0) {
// represents all notes, always first item
return NSOrderedDescending;
}
if ([categoryID1 intValue] < 0) {
// some fixed category
if (categoryID2 < 0) {
// another fixed category
categoryID1 = [NSNumber numberWithInt:abs([categoryID1 intValue])];
categoryID2 = [NSNumber numberWithInt:abs([categoryID2 intValue])];
return [categoryID1 compare:categoryID2];
} else {
// a fixed category is always before a custom one
return NSOrderedAscending;
}
}
if ([categoryID2 intValue] < 0) {
// some fixed category
// and since categoryID1 is not < 0
// a fixed category is always before a custom one
return NSOrderedDescending;
}
// Perform default comparison
return [super compareObject:object1 toObject:object2];
}
Cool Runnings,
Erne._______________________________________________
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