Hi guys,
i’d like to know how remove an element from a scrollView.
Is it possible? How?
Thanks a lot
Hi guys,
i’d like to know how remove an element from a scrollView.
Is it possible? How?
Thanks a lot
-- Create your scrollview -- You have already done this I assume -- Create a rect to add to the scrollView (to demonstrate adding it to the scrollView) local rect = display.newRect(0, 0, 50, 50) scrollView:insert(rect) -- Later on, remove an object from the scrollView scrollView:remove(rect)
Hi!
Thanks for replay!
When I’m adding an element to my scrollview i use this syntax:
local rect = display.newRect( 0, myY, 50, 50 ) scrollView:insert( myindex, rect )
And when I’d like to delete an element i Use this:
scrollView:remove( myindex )
Is It right?
Unfortunately every time i use this a system crush happen ad the error code is just this:
[Finished in 17.9s with exit code -11]
What can i do?
I have the same problem as mentioned by hymn.to.tourach
scrollviews do not to the best of my knowledge have a remove function that allows you to remove things inserted into them.
Things inserted into the scrollview are NOT children of the scrollview itself so doing what you’re doing could result in almost anything that’s contained within the scrollview being removed and is somewhere between unsafe and very dangerous.
You could add something like this
-- Override the remove method for scrollView to remove from the view instead scrollView.\_cachedRemove = scrollView.remove function scrollView:remove( target ) -- if they sent us an index if type(target) == "number" then if isGraphicsV1 then -- call removeself on the thing at that index if self.\_view[target] then self.\_view[target]:removeSelf() else print("WARNING: there IS no object at index ".. target) end else -- call removeself on the thing at that index if self.\_collectorGroup[target] then self.\_collectorGroup[target]:removeSelf() else print("WARNING: there IS no object at index ".. target) end end return elseif type(target) == "table" then -- or if they sent us an object see if it's in the view if isGraphicsV1 then if target.parent == self.\_view then -- then call removeself on it target:removeSelf() else print("WARNING: target was not a child of this scrollview") end else if target.parent == self.\_collectorGroup then -- then call removeself on it target:removeSelf() else print("WARNING: target was not a child of this scrollview") end end end end
under the overridden insert function in widget_scrollview.lua
See elsewhere for how to use your own version of widgets and not the built in one.
What do you mean by “remove from scrollView”?
Do you mean: I want to get rid of the object where it can’t be seen/interacted with?
Or do you mean: I want it to float above the scrollView and when the scrollView moves, the object stays put (or you’re putting it somewhere else on the screen)?
The answers are different depending on what you want to do.
If it’s the first thing, then object:removeSelf() or display.remove( object ) will nuke it from the scrollView.
If its the second thing, then its just a matter of putting the object into a different group. If you’re using composer and your scrollView has been inserted in the scene’s view group, then must put the object in the scene’s view group:
scene.view:insert( object )
Rob
-- Create your scrollview -- You have already done this I assume -- Create a rect to add to the scrollView (to demonstrate adding it to the scrollView) local rect = display.newRect(0, 0, 50, 50) scrollView:insert(rect) -- Later on, remove an object from the scrollView scrollView:remove(rect)
Hi!
Thanks for replay!
When I’m adding an element to my scrollview i use this syntax:
local rect = display.newRect( 0, myY, 50, 50 ) scrollView:insert( myindex, rect )
And when I’d like to delete an element i Use this:
scrollView:remove( myindex )
Is It right?
Unfortunately every time i use this a system crush happen ad the error code is just this:
[Finished in 17.9s with exit code -11]
What can i do?
I have the same problem as mentioned by hymn.to.tourach
scrollviews do not to the best of my knowledge have a remove function that allows you to remove things inserted into them.
Things inserted into the scrollview are NOT children of the scrollview itself so doing what you’re doing could result in almost anything that’s contained within the scrollview being removed and is somewhere between unsafe and very dangerous.
You could add something like this
-- Override the remove method for scrollView to remove from the view instead scrollView.\_cachedRemove = scrollView.remove function scrollView:remove( target ) -- if they sent us an index if type(target) == "number" then if isGraphicsV1 then -- call removeself on the thing at that index if self.\_view[target] then self.\_view[target]:removeSelf() else print("WARNING: there IS no object at index ".. target) end else -- call removeself on the thing at that index if self.\_collectorGroup[target] then self.\_collectorGroup[target]:removeSelf() else print("WARNING: there IS no object at index ".. target) end end return elseif type(target) == "table" then -- or if they sent us an object see if it's in the view if isGraphicsV1 then if target.parent == self.\_view then -- then call removeself on it target:removeSelf() else print("WARNING: target was not a child of this scrollview") end else if target.parent == self.\_collectorGroup then -- then call removeself on it target:removeSelf() else print("WARNING: target was not a child of this scrollview") end end end end
under the overridden insert function in widget_scrollview.lua
See elsewhere for how to use your own version of widgets and not the built in one.
What do you mean by “remove from scrollView”?
Do you mean: I want to get rid of the object where it can’t be seen/interacted with?
Or do you mean: I want it to float above the scrollView and when the scrollView moves, the object stays put (or you’re putting it somewhere else on the screen)?
The answers are different depending on what you want to do.
If it’s the first thing, then object:removeSelf() or display.remove( object ) will nuke it from the scrollView.
If its the second thing, then its just a matter of putting the object into a different group. If you’re using composer and your scrollView has been inserted in the scene’s view group, then must put the object in the scene’s view group:
scene.view:insert( object )
Rob