有方法可以从ScrollView小部件中删除项目吗?

我可以在将其添加到 ScrollView 小部件后访问该项吗?

例如:

local scrollView = widget.newScrollView {...}
scrollView:insert(display.newImage("img1.png", 0, 0))
scrollView:insert(display.newImage("img2.png", 100, 0))

接下来,我想从 scrollView 中删除第1张图像:

scrollView:remove(1) -- 没有效果

更新:我的解决方案:

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])
...
-- 在某些时候,我想删除某些项
scrollView.content[n]:removeSelf()
table.remove(scrollView.content, n)
点赞
用户1979583
用户1979583

你可以这样做:

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)

然后:

img_1:removeSelf()
-- 或者
img_2:removeSelf()

继续编码.................... :)

2013-10-29 18:06:14
用户1300186
用户1300186

为了补充以上回答,你还可以使用:

display.remove( myImage )

这会在移除图像之前检查图像是否为空。

2013-10-29 19:20:50
用户1870706
用户1870706

当调用 display.remove() 或者 object's:removeSelf() 时,会从显示层级中移除该对象。如果你想让该对象保留,但不想将其放在你的 scrollView 中,你可以很简单地将它插入到另一个 display.newGroup() 中,因为显示对象一次只能在一个显示组中。如果你在 Storyboard 中这样做,你可以将它插入到 storyboard 的视图组中。如果你只想摆脱它,调用 display.remove() 或对象的:removeSelf() 是你想要的,只要记得将对它的引用置为 nil。

2013-11-04 01:45:43
用户3373608
用户3373608

使用这个:

Object:removeSelf()

在我的安卓游戏“凤凰泪”中,我多次使用这个方法来清理内存和纹理,以及隐藏物体。

祝好运!

2014-03-03 05:25:04