Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method to remove item from ScrollView widget?

Tags:

lua

coronasdk

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)
like image 888
Константин Тупицин Avatar asked Oct 29 '13 13:10

Константин Тупицин


2 Answers

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.................... :)

like image 190
Krishna Raj Salim Avatar answered Oct 23 '22 07:10

Krishna Raj Salim


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.

like image 1
PersuitOfPerfection Avatar answered Oct 23 '22 07:10

PersuitOfPerfection