• 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
Problems with NSTreeController's removeObjectAtArrangedObjectIndexPath:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with NSTreeController's removeObjectAtArrangedObjectIndexPath:


  • Subject: Problems with NSTreeController's removeObjectAtArrangedObjectIndexPath:
  • From: glenn andreas <email@hidden>
  • Date: Tue, 29 Nov 2005 13:28:39 -0600

So I've got something sort of like PhotoShop layers - basically a tree view that I want to be able to reorder the elements within a given parent (though multiple elements in multiple parents might be selected).

Seems like using removing the object, changing adjusting the index, and re-insert should work. I've got this routine:

- (void) moveLayer: (int) dlayer
{
NSArray *selectedPaths = [myTreeController selectionIndexPaths];
if ([selectedPaths count] == 0 || [selectedPaths containsObject: [NSIndexPath indexPathWithIndex:0]]) {
// nothing selected, or root - do nothing
} else {
NSEnumerator *e = [[[selectedPaths copy] autorelease] objectEnumerator]; // make a copy, since we can end up modifying it
NSIndexPath *index;
while ((index = [e nextObject]) != NULL) {
Layer *obj = [myModel layerAtIndexPath: index];
unsigned int oldIndex = [index indexAtPosition: [index length]-1];
NSIndexPath *movePath = [index indexPathByRemovingLastIndex];
if (dlayer < 0) {
if (oldIndex == 0)
continue; // can't move - already at head
movePath = [movePath indexPathByAddingIndex: oldIndex-1];
} else {
// TBD: check the moving past tail of list...
movePath = [movePath indexPathByAddingIndex: oldIndex+1];
}
NSLog(@"Moving item at %@ to %@", [index description], [movePath description]);
[obj retain];
[myTreeController removeObjectAtArrangedObjectIndexPath:index];
[myTreeController insertObject: obj atArrangedObjectIndexPath: movePath];
[obj release];
}
}
}


So if I have a root item, and two children:

	0
		0,0	A
		0,1	B

and I've got "B" selected, and try to move the layer up (dlayer = -1),:

Moving item at <NSIndexPath 0x4ebaef0:> 2 indexes [0, 1] to <NSIndexPath 0x4ebd700:> 2 indexes [0, 0]

Except the following statement gets logged removeObjectAtArrangedObjectIndexPath

	unexpected state, deleted index != 0

(but this isn't an assert that goes off...) and both items A & B end up vanishing all together...


If I select "A" and try to lower it (dlayer = 1):

Moving item at <NSIndexPath 0x50b2930:> 2 indexes [0, 0] to <NSIndexPath 0x50aff80:> 2 indexes [0, 1]

and that "deleted index != 0" doesn't go off, but instead I get:

	*** -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1)

(and the index(1) is not greater than the number of elements in the array (1))

Any ideas?


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Is Apple's singleton sample code correct?
  • Next by Date: Strange issue copying many files
  • Previous by thread: bug with acceptsFirstMouse: behavior
  • Next by thread: Strange issue copying many files
  • Index(es):
    • Date
    • Thread