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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to