[MacRuby-devel] How to use NSIndexSet with tableView data

Pixoo madpixoo at gmail.com
Sat Oct 23 05:14:00 PDT 2010


That doesn't match what I need.
Ok, here is what I have :

My data is the @items variable which is an array of objects.
My tableView is @tableView.
The action is a reaction to a click on a remove button after a selection in
the table.

What I want to do is something like this :

def removeItems(sender)
  indexes = @tableView.selectedRowsIndexes
  @items.delete_at(indexes)
  @tableView.reloadData
end

But I can't get a way to make it work.

On Sat, Oct 23, 2010 at 2:03 PM, Eloy Duran <eloy.de.enige at gmail.com> wrote:

> Since an Array is a NSArray: http://bit.ly/de3kxd, maybe something
> like the following?
>
> $ macirb
> irb(main):001:0> a = ['apple', 'tuna', 'orange']
> => ["apple", "tuna", "orange"]
> irb(main):002:0> indices = NSIndexSet.indexSetWithIndex(1)
> => #<NSIndexSet:0x20023fe80>
> irb(main):003:0> fish = a.objectsAtIndexes(indices)
> => ["tuna"]
>
> Eloy
>
> On Sat, Oct 23, 2010 at 1:18 PM, Pixoo <madpixoo at gmail.com> wrote:
> > Hi !
> >
> > I'm trying to use a tableView with MacRuby.
> > What I want to do is remove items from my data array based on the
> tableView
> > selection.
> >
> > I used @tableView.selectedRowsIndexes but it returns a NSIndexSet and I
> > don't know how to use it with my array.
> > Can you give me some leads on the subject ?
> >
> > Thanks,
> >
> > _______________________________________________
> > MacRuby-devel mailing list
> > MacRuby-devel at lists.macosforge.org
> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >
> >
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101023/edce85d0/attachment-0001.html>


More information about the MacRuby-devel mailing list