Hi Everyone,
Thanks so much for your contributions to the forum. I am a newbie and need your help.
A text field keeps displaying when i switch to a scene called view 2. The field displays on the top left corner of the tittle bar. The field is not in my code and i have removed all text fields as recommended in the function scene:hide(). I have simplified the code as shown below:
Main.lua
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar ) -- include Corona's "widget" library local widget = require "widget" local composer = require "composer" -- Create title bar at top of the screen local titleBar = display.newImageRect( "tittleBarBack.png", 640, 90 ) img\_titleBar = display.contentWidth/2 titleBar.y = -30 local titleText = display.newText( "My Naira", display.contentCenterX, -1, "Comic Sans MS", 30) --text1:setFillColor( 0 ) -- black -- event listeners for tab buttons: local function onFirstView( event ) currentScene = composer.getSceneName( "current" ) composer.gotoScene( "view1" ) end local function onSecondView( event ) currentScene = composer.getSceneName( "current" ) composer.gotoScene( "view2" ) end local function onThirdView( event ) currentScene = composer.getSceneName( "current" ) composer.gotoScene( "view3" ) end local function onFourthView( event ) currentScene = composer.getSceneName( "current" ) composer.gotoScene( "view4" ) end -- create a tabBar widget with buttons at the bottom of the screen -- table to setup buttons local tabButtons = { { label="Home", labelColor={ default={ 0, 0, 102}, over={0, 0, 102} }, defaultFile="tabBarBack3.png", overFile="tabBarBack3.png", labelYOffset = -6, size= 14, width = 32, height = 32, onPress=onFirstView, selected=true }, { label="Budget", labelColor={ default={ 0, 0, 102}, over={ 0, 0, 102} }, defaultFile="tabBarBack3.png", overFile="tabBarBack3.png", labelYOffset = -6, size= 14, width = 32, height = 32, onPress=onSecondView }, { label="About Us", labelColor={ default={ 0, 0, 102}, over={0, 0, 102} }, defaultFile="tabBarBack3.png", overFile="tabBarBack3.png", labelYOffset = -6, size= 14, width = 32, height = 32, onPress=onThirdView }, { label="Contant Us", labelColor={ default={ 0, 0, 102}, over={ 0, 0, 102} }, defaultFile="tabBarBack3.png", overFile="tabBarBack3.png", labelYOffset = -6, size= 14, width = 32, height = 32, onPress=onFourthView }, } -- create the actual tabBar widget local tabBar = widget.newTabBar( { left = 0, top = display.contentHeight-465, width = 300, height = 40, backgroundFile = "tabBarBack.png", tabSelectedLeftFile = "tabBarBack2.png", tabSelectedRightFile = "tabBarBack2.png", tabSelectedMiddleFile = "tabBarBack2.png", tabSelectedFrameWidth = 30, tabSelectedFrameHeight = 120, buttons = tabButtons } ) onFirstView() -- invoke first tab button's onPress event manually
Budget.lua
----------------------------------------------------------------------------------------- -- -- view2.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist. -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc. -- create a white background to fill screen local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight+100 ) background:setFillColor( 1 ) -- white background:toBack() -- all objects must be added to group (e.g. self.view) sceneGroup:insert( background ) -- Labels for textboxes local monthLabel = display.newText("Month:", 50, 98, native.systemFont, 18) monthLabel:setTextColor(0,0,0) sceneGroup:insert( monthLabel ) local salaryLabel = display.newText("Salary:", 50, 123, native.systemFont, 18) salaryLabel:setTextColor(0,0,0) sceneGroup:insert( salaryLabel ) local otherincomeLabel = display.newText("Other income:", 79, 148, native.systemFont, 18) otherincomeLabel:setTextColor(0,0,0) sceneGroup:insert( otherincomeLabel ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. -- Textboxes to enter data input\_month = native.newTextField(0,0,135,22) input\_month.x = 230 input\_month.y = 100 input\_month.inputType = "default" input\_month.size = 10 input\_month.align = "left" input\_month.placeholder = "Enter Month" input\_salary = native.newTextField(0,0,135,22) input\_salary.x = 230 input\_salary.y = 125 input\_salary.inputType = "number" input\_salary.size = 10 input\_salary.align = "left" input\_salary.placeholder = "Enter Salary Amt." input\_otherincome = native.newTextField(0,0,135,22) input\_otherincome.x = 230 input\_otherincome.y = 150 input\_otherincome.inputType = "number" input\_otherincome.size = 10 input\_otherincome.align = "left" input\_otherincome.placeholder = "Enter Other Income" end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen native.setKeyboardFocus(nil) display.remove(input\_month) display.remove(input\_salary) display.remove(input\_otherincome) end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene
Thanks indeed.
Folusho.