Iterating over the children of a ScrollView

Hi there,

In previous app’s I use a lot of display groups (using display.newGroup) and I can easily iterate over the children to identify individual elements using the following function.

function WTF.findWidgetById(view,id)     -- Walk the view looking for an element with a matching ID!     print("FWBID View ", view , "has "..view.numChildren.." children, looking for "..id)     local w     for i=1,view.numChildren do         w = view[i]         print("Child "..i.." is ",w,w.id)         if id == w.id then return w end     end     print("ERROR - widget "..id.." not found in view")     return nil end

In the latest version I’m replacing some display groups with widget.newScrollView() items instead.  According to the doc’s the scrollView widget extends a display group, but when I try using the above function to iterate over the inserted objects in my scroll view - I can’t find them, all I get is a list of three children regardless of how many items I added.

Is there a “hidden” field inside the scroll view that will allow me to iterate over the display objects / widgets inserted into a scroll view (note : I tried the :getView() method and it didn’t seem to work).

This is on the latest stable build.

Thanks in advance.

Hi @techdojo,

Try doing the .numChildren on this element of the scrollView:

[lua]

scrollView._collectorGroup

[/lua]

Brent

Hi Brent,

That works perfectly - thanks :slight_smile:

Hi @techdojo,

Try doing the .numChildren on this element of the scrollView:

[lua]

scrollView._collectorGroup

[/lua]

Brent

Hi Brent,

That works perfectly - thanks :slight_smile: