Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jun 30, 2009, 12:02 PM   #1
macrumors 6502a
Join Date: Jun 2005
Location: West-Europe
nstreecontroller rearrangeobjects bug?

Hi folks

I have my own NSTreeController and NSOutlineView subclass, with a coredata backend. I can drag and drop objects around and each object knows it position.

When I change something (add/remove/drag&drop) the position is correctly updated, but the view is not. [myTreeController rearrangeobjects] is called, but only the top group (with parent == nil) is automatically rearranged. All the subgroups are not.

My question is this. Did I overlook something, or is this a bug with NSTreeController? Does this problem sound familiar to you? NSTreeController has had a lot of bugs in the past, from what I can tell. Running 10.5.7 on intel.

thanks for reading
MrFusion is offline   0 Reply With Quote
Old Aug 14, 2009, 12:23 PM   #2
Thread Starter
macrumors 6502a
Join Date: Jun 2005
Location: West-Europe
I am trying to fix this bug once more, but with no luck so far. Maybe one of you sees the problem?

The bug is this. Adding a new node to a folder, when one of the nodes of that folder is selected, will add a new node to the tree with the correct value for the position. However, in the NSOutlineView the node is not correctly positioned in the tree.

-(id) addManagedObject:(NSString *) entityName {
	// First get selected object, then add new object. this returns the correct user selection!
	id parent = ([[self selectedObjects] count] > 0) ? [[self selectedObjects] objectAtIndex:0] : nil;
	int position = def_newNodePosition;
	if (parent && ![parent isFolder]) { //parent is a node itself, use its parent instead. rootnode = nil and a folder <if (![parent isFolder])> is true for rootnode
		position = [[parent valueForKey:@"position"] intValue] + def_incrementNodePosition;
		parent = [parent parent];
	return [self addManagedObject:entityName toParent:parent atPosition:position];

-(id) addManagedObject:(NSString *) entityName toParent:(id) parent atPosition:(int) position {
	id newNode = [NSEntityDescription insertNewObjectForEntityForName:entityName
 											   inManagedObjectContext:[self managedObjectContext]];  //Add a new node into the tree.
	[newNode setParent:parent];
	[newNode setValue:[NSNumber numberWithInt:position]
	[self resetPositionsFor:parent];
	[[self managedObjectContext] processPendingChanges]; //to speed up display of new node
	return newNode;

#pragma mark (re)order data
-(void) resetPositionsFor:(id)node {
	if (node) {
		[node resetPositions];
	} else {
		NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Group" 
															 inManagedObjectContext:[self managedObjectContext]];
		NSFetchRequest *request = [[NSFetchRequest alloc] init];
		[request setEntity:entityDescription];
		[request setIncludesSubentities:YES];
		NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"parent == nil"]];
		[request setPredicate:pred];
		NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"position"
		[request setSortDescriptors:[NSArray arrayWithObject:sort]];
		NSError *error = nil;
		NSArray *ordered = [[self managedObjectContext] executeFetchRequest:request
		[request release];
		//reset position of children
		for (int i = 0; i < [ordered count]; i++) {
			id item = [ordered objectAtIndex:i];
			[item setValue:[NSNumber numberWithInt:i*def_positioninterval]
			[item resetPositions]; //reset positions of childrenchildren of this child
		[sort release];

	//re-order and reload
	[self rearrangeObjects];
	[myOutlineView reloadData];
MrFusion is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac OS Lion Developer 3 Bug -BigMac- Mac OS X 10.7 Lion 2 May 31, 2011 07:53 AM
Mac OS Lion dev. 3 bug -BigMac- Mac OS X 10.7 Lion 0 May 8, 2011 06:39 AM
iTunes bug report mmmdreg Mac Applications and Mac App Store 0 Mar 19, 2011 05:52 AM
iTunes shortcomings and bugs in the Apple music database nss.aries Mac Applications and Mac App Store 6 Mar 3, 2011 09:35 PM
iOS 4.3 New app update design and bugs. GollumBoy iPhone 10 Jan 15, 2011 08:18 AM

All times are GMT -5. The time now is 06:46 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC