• 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: NSTreeController problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTreeController problems


  • Subject: Re: NSTreeController problems
  • From: Jonathan Dann <email@hidden>
  • Date: Mon, 19 May 2008 00:44:24 +0100


On 18 May 2008, at 23:57, Charles Srstka wrote:

On May 18, 2008, at 5:47 PM, Jonathan Dann wrote:

Not any more, the documentation may not have been updated yet. The header for NSTreeController says differently as of 10.5. It's always good to check the docs and the comments in the header file. (control double click on the word NSTreeController in your code to get to the header). You often find the odd method that's not in the docs too. File a radar if you do for any of the classes you use.

Glad to be of service, feel free to ask more.

Jon

Oh sweet, you are indeed correct. The header also mentions a - descendantNodeAtIndexPath: method I can send this object that will allow me to get the node at a given index path, which was another thing I was having trouble doing.


Thanks! :-)

Charles

Yeah that one's really useful. NSTreeController is so much easier to use in 10.5 but those extensions to NSTreeController NSTreeNode and NSIndexPath make it really simple to use.


You're welcome. These ones I didn't post but I use ALL the time too (note they call other methods in the sample project)

//NSTreeNode_Extensions (insipred by Apple's SourceView sample code)
- (NSArray *)descendants;
{
	NSMutableArray *array = [NSMutableArray array];
	for (NSTreeNode *item in [self childNodes]) {
		[array addObject:item];
		if (![item isLeaf])
			[array addObjectsFromArray:[item descendants]];
	}
	return [[array copy] autorelease];
}

// NSTreeController_Extensions
- (void)setSelectedNode:(NSTreeNode *)node;
{
	[self setSelectionIndexPath:[node indexPath]];
}

- (void)setSelectedObject:(id)object;
{
	[self setSelectedNode:[self treeNodeForObject:object]];
}

- (NSArray *)flattenedSelectedNodes;
{
NSMutableArray *mutableArray = [NSMutableArray array];
for (NSTreeNode *treeNode in [self selectedNodes]) {
if (![mutableArray containsObject:treeNode])
[mutableArray addObject:treeNode];
if (![[treeNode valueForKeyPath:[self leafKeyPath]] boolValue]) {
[mutableArray addObjectsFromArray:[treeNode valueForKeyPath:@"descendants"]];
}
}
return [[mutableArray copy] autorelease];
}


- (NSArray *)flattenedSelectedObjects;
{
return [[self flattenedSelectedNodes] valueForKey:@"representedObject"];
}


- (NSArray *)flattenedSelectedLeafNodes;
{
	NSMutableArray *mutableArray = [NSMutableArray array];
	for (NSTreeNode *treeNode in [self flattenedSelectedNodes]) {
		if ([[treeNode valueForKeyPath:[self leafKeyPath]] boolValue])
			[mutableArray addObject:treeNode];
	}
	return [[mutableArray copy] autorelease];
}

- (NSArray *)flattenedSelectedLeafObjects;
{
return [[self flattenedSelectedLeafNodes] valueForKey:@"representedObject"];
}


- (NSArray *)flattenedSelectedGroupNodes;
{
	NSMutableArray *mutableArray = [NSMutableArray array];
	for (NSTreeNode *treeNode in [self flattenedSelectedNodes]) {
		if (![[treeNode valueForKeyPath:[self leafKeyPath]] boolValue])
			[mutableArray addObject:treeNode];
	}
	return [[mutableArray copy] autorelease];
}


- (NSArray *)flattenedSelectedGroupObjects;
{
return [[self flattenedSelectedGroupNodes] valueForKey:@"representedObject"];
}


Jon

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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:
    • Re: NSTreeController problems
      • From: Charles Srstka <email@hidden>
References: 
 >NSTreeController problems (From: Charles Srstka <email@hidden>)
 >Re: NSTreeController problems (From: Jonathan Dann <email@hidden>)
 >Re: NSTreeController problems (From: Charles Srstka <email@hidden>)
 >Re: NSTreeController problems (From: Jonathan Dann <email@hidden>)
 >Re: NSTreeController problems (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: validateMenuItem() not always being called
  • Next by Date: Re: NSTreeController problems
  • Previous by thread: Re: NSTreeController problems
  • Next by thread: Re: NSTreeController problems
  • Index(es):
    • Date
    • Thread