Input field on one tab is showing up on another tab.

Hi,

I am using iOS, with a 4 tab screen. On one tab I create an input field and it appears to work, but when I select the other tabs the input field shows up on those tabs. I added the object to the group, but it does not disappear when I exit that tab for another one (the numberField display). Here is some of the code:

Thanks for the help.

local numberField local titleLoc = 75 -- NumberField Listener local function numberHandler( event ) if ( "began" == event.phase ) then -- This is the "keyboard has appeared" event elseif ( "ended" == event.phase ) then -- This event is called when the user stops editing a field: -- for example, when they touch a different field or keyboard focus goes away --print( "Text entered = " .. tostring( numberField.text ) ) -- display the text entered server = numberField.text; elseif ( "submitted" == event.phase ) then -- This event occurs when the user presses the "return" key -- (if available) on the onscreen keyboard -- Hide keyboard native.setKeyboardFocus( nil ) end end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- create a white background to fill screen local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) bg:setFillColor( 255 ) -- white -- create some text local title = display.newText( "IP Address", 0, 0, native.systemFont, 32 ) title:setTextColor( 0, 0, 255 ) -- blue title:setReferencePoint( display.CenterReferencePoint ) title.x = display.contentWidth \* 0.5 title.y = titleLoc -- ======================================================================== -- Create our Text Field numberField = native.newTextField( 15, titleLoc + 40, 300, 50 ) numberField.userInput = numberListener numberField.inputType = "number" numberField.text = server numberField:addEventListener( "userInput", numberHandler ) numberField.font = native.newFont( native.systemFont, 32 ) native.setKeyboardFocus( numberField ) -- all objects must be added to group (e.g. self.view) group:insert( bg ) group:insert( title ) group:insert( numberField ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view numberField.text = server end -- Called when scene is about to move off screen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) numberField:removeEventListener( "userInput", numberHandler ) native.setKeyboardFocus( nil ) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end

Here is the only way I was able to get this to work:

local numField local titleLoc = 75 -- NumberField Listener local function numberListener( event ) if ( "began" == event.phase ) then -- This is the "keyboard has appeared" event elseif ( "ended" == event.phase ) then -- This event is called when the user stops editing a field: -- for example, when they touch a different field or keyboard focus goes away --print( "Text entered = " .. tostring( numberField.text ) ) -- display the text entered gd.server = numField.text; elseif ( "submitted" == event.phase ) then -- This event occurs when the user presses the "return" key -- (if available) on the onscreen keyboard -- Hide keyboard native.setKeyboardFocus( nil ); end end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- create a white background to fill screen local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) bg:setFillColor( 255 ) -- white -- create some text local title = display.newText( "Broker IP Address", 0, 0, native.systemFont, 32 ) title:setTextColor( 0, 0, 255 ) -- blue title:setReferencePoint( display.CenterReferencePoint ) title.x = display.contentWidth \* 0.5 title.y = titleLoc -- ======================================================================== -- Create our Text Field numField = native.newTextField( 15, titleLoc + 40, 300, 50 ) numField.userInput = numberListener numField.inputType = "number" numField.text = gd.server numField:addEventListener( "userInput", numField ) numField.font = native.newFont( native.systemFont, 32 ) native.setKeyboardFocus( numField ) -- all objects must be added to group (e.g. self.view) group:insert( bg ) group:insert( title ) group:insert( numField ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view if ( numField == nil ) then numField = native.newTextField( 15, titleLoc + 40, 300, 50 ) numField.userInput = numberListener numField.inputType = "number" numField.text = gd.server numField:addEventListener( "userInput", numField ) numField.font = native.newFont( native.systemFont, 32 ) native.setKeyboardFocus( numField ) end end -- Called when scene is about to move off screen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) if ( numField ~= nil ) then numField:removeSelf() numField = nil end end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view print("destroyScene: Called"); -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene

Any API call that begins with “native” is a native object and not part of the OpenGL canvas that all of Corona’s display functions live in.  Therefore Storyboard cannot manage them.  You have to manually add and remove them in the enterScene and exitScene functions.

Thanks, I figure that point out and glad it was the right way.

Any API call that begins with “native” is a native object and not part of the OpenGL canvas that all of Corona’s display functions live in.  Therefore Storyboard cannot manage them.  You have to manually add and remove them in the enterScene and exitScene functions.

Thanks, I figure that point out and glad it was the right way.