问题
I'm trying to nest pages and such with button presses in an app I am working on. However, as a widget, it carries over and such and must be removed using display.remove() or :removeSelf. I'm trying to make these buttons delete/remove themselves from the view as they are pressed and the next page is loaded, but when I do this it either does not work, or throws a runtime error. Suggestions?
Edit: This is what I am currently using, although it leaves the button gone permanently after click. `
local onButtonEvent = function (event )
if event.phase == "release" then
display.remove( myButton )
myButton = nil
display.remove( buttonGroup )
buttonGroup = nil
storyboard.gotoScene( "shape" )
end
end
回答1:
Here's another way. Why don't you set
myButton.isVisible = false
inside your onButtonEvent function.
And I've never used StoryBoard, but I'm pretty sure there is a event fired ("willEnterScene" I think) when you enter the scene.
So you can set mybutton.isVisible = true
there
回答2:
this will work in lua/ Corona:
MyButton:removeSelf( )
removes it completely.
Hope that helps !
来源:https://stackoverflow.com/questions/10883570/button-removal-in-corona