• 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
Bound NSTreeNode - Inserting Children
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bound NSTreeNode - Inserting Children


  • Subject: Bound NSTreeNode - Inserting Children
  • From: Robert Sesek <email@hidden>
  • Date: Wed, 11 Jun 2008 15:50:48 -0400

Hi all,

I have bound a NSTreeController to a NSOutlineView. I am trying to insert child nodes into this structure, but I cannot seem to make it work. This is the code I originally used:

- (void)addChildren:(NSArray *)children toNode:(NSTreeNode *)node
{
	NSXMLElement *parent = [node representedObject];
	for (NSXMLNode *child in children)
	{
		[parent addChild:child];
	}

	[registerController rearrangeObjects];
}

I figured by updating the NSXML* model and then rearranging it should work, but it didn't. So I then wrote code to take advantage of NSTreeNode in 10.5:

- (void)addChildren:(NSArray *)children toNode:(NSTreeNode *)node
{
NSMutableArray *childNodes = [node mutableChildNodes];
[childNodes removeAllObjects];
for (NSXMLNode *child in children)
{
NSTreeNode *newChild = [[NSTreeNode alloc] initWithRepresentedObject:child];
[childNodes addObject:newChild];
[newChild release];
}
}


But this results in this exception: -[NSKeyValueFastMutableArray2 count]: value for key children of object 0x105a220 is nil:
#0 0x91bdd0d7 in objc_exception_throw
#1 0x94827f2b in +[NSException raise:format:arguments:]
#2 0x94827f6a in +[NSException raise:format:]
#3 0x944b5061 in -[NSKeyValueFastMutableArray2 _nonNilArrayValueWithSelector:]
#4 0x944b4fa9 in -[NSKeyValueFastMutableArray2 count]
#5 0x9455c5a7 in -[NSKeyValueNotifyingMutableArray addObject:]
#6 0x96f6769f in -[NSTreeControllerTreeNode insertObject:inSubNodesAtIndex:]
#7 0x944b50af in -[NSKeyValueFastMutableArray insertObject:atIndex:]
#8 0x944b4f74 in -[NSKeyValueFastMutableArray addObject:]
#9 0x0000446a in -[DebuggerWindowController addChildren:toNode:] at DebuggerWindowController.m:278


I've also tried to insert using index paths, but this, too, results with the above crash:

- (void)addChildren:(NSArray *)children toNode:(NSTreeNode *)node
{
[[node mutableChildNodes] removeAllObjects];
NSIndexPath *ip = [node indexPath];
for (NSXMLNode *child in children)
{
NSTreeNode *newChild = [[NSTreeNode alloc] initWithRepresentedObject:child];
[registerController insertObject:child atArrangedObjectIndexPath:[ip indexPathByAddingIndex:0]];
[newChild release];
}
}


I have no other ideas for how to get this to work. Basically, the tree displayed is incomplete, and as the user expands the tree, data is fetched from a server and then inserted beneath a node.

Thanks,
Robert
_______________________________________________

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: Bound NSTreeNode - Inserting Children
      • From: "Hamish Allan" <email@hidden>
  • Prev by Date: Re: Documenting projects
  • Next by Date: Re: Loading a nib
  • Previous by thread: RE: Loading a nib
  • Next by thread: Re: Bound NSTreeNode - Inserting Children
  • Index(es):
    • Date
    • Thread