• 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: NSTableView Drag & Drop... Well, Maybe
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTableView Drag & Drop... Well, Maybe
      • From: Brian Webster <email@hidden>
References: 
 >Re: NSTableView Drag & Drop... Well, Maybe (From: Brian Webster <email@hidden>)

  • Prev by Date: Re: NSTableView Drag & Drop... Well, Maybe
  • Next by Date: Re: NSTableView Drag & Drop... Well, Maybe
  • Previous by thread: Re: NSTableView Drag & Drop... Well, Maybe
  • Next by thread: Re: NSTableView Drag & Drop... Well, Maybe
  • Index(es):
    • Date
    • Thread