• 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 delete multiple selected rows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView delete multiple selected rows


  • Subject: Re: NSTableView delete multiple selected rows
  • From: Max Horn <email@hidden>
  • Date: Sat, 15 Dec 2001 09:31:46 +0100

At 23:08 Uhr -0800 14.12.2001, Sam Goldman wrote:
There might be a simpler way (could try to get an NSRange for selected,
dunno if it exists).

It seems to me that this would be pretty simple to imagine, at least if you
have done other programming. Maybe the fact that it's object-oriented is
tripping you up. If so, just think about deleting items in one array from
another.

--------------

int numRows = [tableView numberOfRows] - 1; // I don't remember if I need
to take away 1 or not.
int i = 0;

while(int i < numRows)
{
if ([tableView isRowSelected: i])
[myDataSourceArray removeObjectAtIndex: i];
int i++;
}

[tableView reloadData];

This code is *NO* good!

Besides the obvious mistakes (int i++; instead of i++; or "while (int i...)) this will not work at all, because when you start removing stuff from the array, you change the indices of it! Hence you first remove the wrong objects, and finally you will get an index out of bounds exception if you remove e.g. the last item as one of several.

So either do this (it's not test either, so it might be no good, too <g>):


int i = [tableView numberOfRows];
while(i-- > 0)
{
if ([tableView isRowSelected:i])
[myDataSourceArray removeObjectAtIndex:i];
}
[tableView reloadData];



Or you can use - (void)removeObjectsFromIndices:(unsigned *)indices numIndices:(unsigned)count. You will have to use an array of unsigned ints, representing the indices you want to remove. As to "how do you get it" - well, you have to create it yourself :)


Max
--
-----------------------------------------------
Max Horn
Software Developer

email: <mailto:email@hidden>
phone: (+49) 6151-494890


  • Follow-Ups:
    • Re: NSTableView delete multiple selected rows
      • From: Charles Srstka <email@hidden>
References: 
 >Re: NSTableView delete multiple selected rows (From: Sam Goldman <email@hidden>)

  • Prev by Date: Re: NeXTWORLD floppy disk, anyone?
  • Next by Date: Re: NSTableView delete multiple selected rows
  • Previous by thread: Re: NSTableView delete multiple selected rows
  • Next by thread: Re: NSTableView delete multiple selected rows
  • Index(es):
    • Date
    • Thread