Or can I get access an item after adding it to ScrollView
widget?
Example:
local scrollView = widget.newScrollView {...}
scrollView:insert(display.newImage("img1.png", 0, 0))
scrollView:insert(display.newImage("img2.png", 100, 0))
Next I want to remove 1st image from scrollView
:
scrollView:remove(1) -- has no effect
Update: My solution:
local scrollView = widget.newScrollView {...}
scrollView.content = {}
scrollView.content[#scrollView.content+1]= display.newImage("img1.png", 0, 0)
scrollView:insert(scrollView.content[#scrollView.content])
scrollView.content[#scrollView.content+1]= display.newImage("img2.png", 0, 0)
scrollView:insert(scrollView.content[#scrollView.content])
...
-- at some point I want to delete some item
scrollView.content[n]:removeSelf()
table.remove(scrollView.content, n)
You can do like this:
local scrollView = widget.newScrollView {...}
local img_1 = display.newImage("img1.png", 0, 0)
local img_2 = display.newImage("img2.png", 100, 0)
scrollView:insert(img_1)
scrollView:insert(img_2)
Then:
img_1:removeSelf()
-- or
img_2:removeSelf()
Keep coding.................... :)
To add on to the answer above, you may also use:
display.remove( myImage )
This checks if the image is not nil before removing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With