• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 'Static' items in an NSOutlineView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • iOS 5 and XCode 3.2.6
      • From: Dave <email@hidden>
References: 
 >'Static' items in an NSOutlineView (From: Koen van der Drift <email@hidden>)
 >Re: 'Static' items in an NSOutlineView (From: Quincey Morris <email@hidden>)
 >Re: 'Static' items in an NSOutlineView (From: Koen van der Drift <email@hidden>)
 >Re: 'Static' items in an NSOutlineView (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Exception when entering too big value in text field (with number formatter)
  • Next by Date: iOS 5 and XCode 3.2.6
  • Previous by thread: Re: 'Static' items in an NSOutlineView
  • Next by thread: iOS 5 and XCode 3.2.6
  • Index(es):
    • Date
    • Thread