You should not try and remove the scene you’re currently in.
Also keep in mind, scene:show() gets called twice each time you call composer.gotoScene(). It gets called once before the scene transitions on the screen. This is the “will” phase. In fact, the “event” table being passed to the show function will have an entry called “event.phase” that you can test against. Before the scene comes on screen, this will be set to “will”. After the scene is on screen, you will get a second call to scene:show(), but this time event.phase will equal “did” indicating that the scene is fully on the screen.
i.e.
local myTextField -- needs to be local to the whole module. function scene:show( event ) local sceneGroup = self.view if event.phase == "did" then -- scene is fully on screen myTextField = native.newTextField( . . . ) sceneGroup:insert( myTextField ) end end
Then in scene:hide()
function scene:hide( event ) local sceneGroup = self.view if event.phase == "will" then -- before the scene is transitioned away. myTextField:removeSelf() myTextField = nil end end
Rob