Row moving [source]
Row moving [source]
- Subject: Row moving [source]
- From: Herr Witten <email@hidden>
- Date: Sun, 1 Feb 2004 21:50:20 -0500
Here are some useful methods based on Daryn's code, but for an
NSArrayController:
- (void)moveObjectFromIndex: (unsigned)index toIndex: (unsigned)newIndex
{
if (index == newIndex)
return;
NSMutableArray* content = [self content];
[content insertObject: [content objectAtIndex: index] atIndex:
newIndex];
[self removeObjectAtArrangedObjectIndex: (index < newIndex) ? index
: index + 1];
}
- (void)moveObjectsFromIndexes: (NSIndexSet*)indexes toIndex:
(unsigned)newIndex
{
unsigned biggestIndex = [indexes lastIndex];
int indexOffset = 0;
for (unsigned index = [indexes firstIndex]; index != NSNotFound;
index = [indexes indexGreaterThanIndex: index])
{
if (biggestIndex <= newIndex)
[self moveObjectFromIndex: index + indexOffset toIndex:
newIndex];
else
[self moveObjectFromIndex: index toIndex: newIndex -
indexOffset];
indexOffset--;
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.