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

2010-10-23 Thread Pixoo
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
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


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

2010-10-23 Thread Pixoo
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  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)
> => #
> irb(main):003:0> fish = a.objectsAtIndexes(indices)
> => ["tuna"]
>
> Eloy
>
> On Sat, Oct 23, 2010 at 1:18 PM, Pixoo  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
> > [email protected]
> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >
> >
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


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

2010-10-23 Thread Pixoo
I already looked at those functions but I couldn't believe there was no way
to obtain a simple array of the indexes list.
I seams that's the case...

Thanks,

On Sat, Oct 23, 2010 at 2:31 PM, Alistair Holt wrote:

> As always, the docs are your friend. Look up the enumeration methods in
>
> http://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Classes/NSIndexSet_Class/Reference/Reference.html
>
> --
> Alistair Holt
>
>
> On 23 Oct 2010, at 13:14, Pixoo  wrote:
>
> > NSIndexSet
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


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

2010-10-23 Thread Pixoo
Ok it worked \o/
I'm pretty new at ObjC (therefore I use MacRuby :D) so I don't know NS
objects.

Thanks again :)

On Sat, Oct 23, 2010 at 2:43 PM, Eloy Duran  wrote:

> You’re right, I forgot to include the line that basically did: @items
> -= fish. However, since an array is actually of the mutable type
> NSMutableArray, you can use its API as well http://bit.ly/90436W.
>
> irb(main):007:0> a.removeObjectsAtIndexes(indices)
> => ["apple", "orange"]
>
> If you find you need to work with NSIndexSet's a lot, you could go to
> town and add this to NSIndexSet: http://gist.github.com/642166
>
> HTH,
> Eloy
>
> On Sat, Oct 23, 2010 at 2:14 PM, Pixoo  wrote:
> > 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 
> 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)
> >> => #
> >> irb(main):003:0> fish = a.objectsAtIndexes(indices)
> >> => ["tuna"]
> >>
> >> Eloy
> >>
> >> On Sat, Oct 23, 2010 at 1:18 PM, Pixoo  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
> >> > [email protected]
> >> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >> >
> >> >
> >> ___
> >> MacRuby-devel mailing list
> >> [email protected]
> >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >
> >
> > ___
> > MacRuby-devel mailing list
> > [email protected]
> > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> >
> >
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel