• 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
Re: NSArrayController Funkyness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController Funkyness


  • Subject: Re: NSArrayController Funkyness
  • From: Daryn <email@hidden>
  • Date: Sat, 31 Jan 2004 01:10:32 -0600

On Jan 30, 2004, at 8:21 PM, Herr Witten wrote:
> I am providing drag and drop capabilities in my tables so that rows can
> be moved around. Thus, in the the
>
> - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id
> <NSDraggingInfo>)info row:(int)row
> dropOperation:(NSTableViewDropOperation)operation
>
> method, I need to insert the "new" objects (unarchived) and remove the
> "old" objects afterward. [...] Neither
> can use indexes, because there is a modification to the array.

Not true. Here's a category I wrote long ago for table dnd. Customize
it to your liking:

@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

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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: 
 >NSArrayController Funkyness (From: Herr Witten <email@hidden>)
 >Re: NSArrayController Funkyness (From: mmalcolm crawford <email@hidden>)
 >Re: NSArrayController Funkyness (From: Herr Witten <email@hidden>)
 >Re: NSArrayController Funkyness (From: mmalcolm crawford <email@hidden>)
 >Re: NSArrayController Funkyness (From: Herr Witten <email@hidden>)

  • Prev by Date: Re: NSArrayController Funkyness
  • Next by Date: Re: Using NSScrollView at run time
  • Previous by thread: Re: NSArrayController Funkyness
  • Next by thread: Re: NSArrayController Funkyness
  • Index(es):
    • Date
    • Thread