RE: NSTableView Drag & Drop... Well, Maybe
RE: NSTableView Drag & Drop... Well, Maybe
- Subject: RE: NSTableView Drag & Drop... Well, Maybe
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Tue, 8 Oct 2002 15:47:06 -0400
>
> NSEnumerator *e = [tv selectedRowEnumerator];
[snip]
>
> while(index = [e nextObject]) {
>
> [employees removeObjectAtIndex:[index intValue]];
>
> }
>
>
There is a problem with this loop here. Each time you remove an object
>
from the employees array, the index of all the employees after the one
>
that is removed will shift down by one. Then, when you go to the next
>
selected row, it will no longer refer to the same person.
>
>
For example, if rows 1 and 3 are selected, removing row 1 will shift
>
the employee who was at row 3 down to row 2. Then, when you remove the
>
employee that is _now_ at row 3, you're actually removing the employee
>
that _was_ at row 4. You'll have to adjust your indices as you remove
>
each person in order to compensate for this.
>
Another solution is to enumerate backwards, deleting row 3 and then row 1.
Row 1 stays at row 1 even after you delete row 3, so you don't have to
adjust for the number of deletions you have made. You could probably
(haven't tested this myself) fix the problem with:
NSEnumerator *e = [[[tv selectedRowEnumerator] allObjects]
reverseObjectEnumerator];
Jonathan
_______________________________________________
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.