Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Row dragging ...



Since you are simply doing intra-table rearrangement, you can simplify the process by noting the objects to be moved and then simply moving them with code like this provided by Daryn, obviating the need to encode your objects:

@implementation NSMutableArray (MyArrayAdditions)

-(void)moveObjectAtIndex:(unsigned)index toIndex:(unsigned)newIndex {
[self moveObjectsFromIndices:&index numIndices:1 toIndex:newIndex];
}

-(void)moveObjectsFromIndices:(unsigned *)indices numIndices:(unsigned)count toIndex:(unsigned)index {
unsigned off1 = 0, off2 = 0;

while (count--) {
unsigned i = *indices++;

if (i < index) {
i -= off1++;
[self insertObject:[self objectAtIndex:i] atIndex:index];
[self removeObjectAtIndex:i];
} else {
[self insertObject:[self objectAtIndex:i] atIndex:index+off2++];
[self removeObjectAtIndex:i+1];
}
}
}

@end

On 31 Jan 2004, at 4:44 PM, J Nozzi wrote:

I've been searching and searching and unable to find a clear, concise answer to the following:

How in the world do you make an NSTableView able to respond to row drags? I want the user to be able to re-order rows (not columns) with a drag operation.

If anyone has a very simple explanation, I'd be most appreciative.
_______________________________________________
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.

References: 
 >Row dragging ... (From: J Nozzi <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.