HELPPPPPPPP!

When I transition from the bandProfile screen and then return to it, my text box is gone and to further the problem; When I try another tab upon returning to the Profile tab for a second time I get a crash, WTF?!?!?

Below is the Main.lua and the bandProfile.lua

… am I just a messy programmer or… stupid… or all of the above :) 

– Alpha

– Version: 1.0

– 

– Copyright © 2013 Soundstache,Inc

– Bela` Hackman, Nick Redmond


local storyboard = require ( “storyboard” )

local widget = require( “widget” )

display.setStatusBar( display.HiddenStatusBar )


– Create buttons table for the tab bar

local tabButtons = 

{

    {

        width = 32, height = 32,    

        defaultFile = “assets/tabIcon.png”,

        overFile = “assets/tabIcon-down.png”,

        label = “Profile”,

        onPress = function() storyboard.gotoScene( “bandProfile” ); 

            display.remove( splash )

            end,

        selected = true

    },

    

    {

        width = 32, height = 32,    

        defaultFile = “assets/tabIcon.png”,

        overFile = “assets/tabIcon-down.png”,

        label = “GPS”,

        onPress = function() storyboard.gotoScene( “screen1” ); 

            audio.play(backgroundMusic);

            display.remove( splash )

            end,

        selected = false

    },

    {

        width = 32, height = 32,

        defaultFile = “assets/tabIcon.png”,

        overFile = “assets/tabIcon-down.png”,

        label = “List”,

        onPress = function() storyboard.gotoScene( “screen2” ); 

            display.remove( splash )

            end,

            

    },

    {

        width = 32, height = 32,

        defaultFile = “assets/tabIcon.png”,

        overFile = “assets/tabIcon-down.png”,

        label = “Maps”,

        onPress = function() storyboard.gotoScene( “screen4” ); 

            display.remove( splash )

            end,

    }

}

–Create a tab-bar and place it at the bottom of the screen

local demoTabs = widget.newTabBar

{

    top = display.contentHeight - 50,

    width = display.contentWidth,

    backgroundFile = “assets/tabbar.png”,

    tabSelectedLeftFile = “assets/tabBar_tabSelectedLeft.png”,

    tabSelectedMiddleFile = “assets/tabBar_tabSelectedMiddle.png”,

    tabSelectedRightFile = “assets/tabBar_tabSelectedRight.png”,

    tabSelectedFrameWidth = 20,

    tabSelectedFrameHeight = 52,

    buttons = tabButtons

}

– Start at home

storyboard.gotoScene( “bandProfile” )

############AND NOW THE bandPROFILE module

– Alpha

– Version: 1.0

– 

– Copyright © 2013 Soundstache,Inc

– Bela` Hackman, Nick Redmond


local storyboard = require “storyboard”

local widget = require( “widget” )

local scene = storyboard.newScene()

    local isAndroid = “Android” == system.getInfo(“platformName”)

    local inputFontSize = 18

    local inputFontHeight = 30

    tHeight = 100

    

    local tableView = widget.newTableView

    {

        top = 190,

        width = 320, 

        height = 120,

        maskFile = “assets/mask-320x366.png”,

        listener = tableViewListener,

    }

    – Create 100 rows

    for i = 1, 3 do

        local isCategory = false

        local rowHeight = 40

        local rowColor = 

        {

            default = { 255, 255, 255 },

            over = { 255, 0, 255 },

        }

        local lineColor = { 220, 220, 220 }

        – Make some rows categories

        if i == 25 or i == 50 or i == 75 then

            isCategory = true

            rowHeight = 24

            rowColor = 

            { 

                default = { 150, 160, 180, 200 }

            }

        end

        – Insert the row into the tableView

        tableView:insertRow

        {

            isCategory = isCategory,

            rowHeight = rowHeight,

            rowColor = rowColor,

            lineColor = lineColor,

        }

    end

    

    if isAndroid then

        – Android text fields have more chrome. It’s either make them bigger, or make the font smaller.

        – We’ll do both

        inputFontSize = 14

        inputFontHeight = 42

        tHeight = 40

    end

    

    local function fieldHandler( textField )

        

        return function( event )

            if ( “began” == event.phase ) then

                – This is the “keyboard has appeared” event

                – In some cases you may want to adjust the interface when the keyboard appears.

        

            elseif ( “ended” == event.phase ) then

                – This event is called when the user stops editing a field: for example, when they touch a different field

            

            elseif ( “editing” == event.phase ) then

        

            elseif ( “submitted” == event.phase ) then

                – This event occurs when the user presses the “return” key (if available) on the onscreen keyboard

                print( textField().text )

            

                – Hide keyboard

                native.setKeyboardFocus( nil )

            end

        end

    end

local defaultField

    

    

    local bkgd = display.newRect( 78, 78, display.contentWidth, display.contentHeight )

    bkgd:setFillColor( 10, 30, 180, 0 )        – set Alpha = 0 so it doesn’t cover up our buttons/fields

    – Tapping screen dismisses the keyboard

    –

    – Needed for the Number and Phone textFields since there is

    – no return key to clear focus.

    local listener = function( event )

        – Hide keyboard

        print(“tap pressed”)

        native.setKeyboardFocus( nil )

    

        return true

    end

function scene:createScene( event )

    local group  = self.view

    

    

    

    display.setDefault( “background”, 187, 216, 125 )

    

    t = {}                          – create a table

    k = “x”

    t[k] = 3.14                     – new table entry, with key=“x” and value=3.14

    t[10] = “hi”            – new table entry, with key=10 and value=“hi”

    print( t[k] )           --> 3.14

    print( t[“x”] )         --> 3.14

    print( t.x )            --> 3.14

    k=10

    print( t[k] )           --> “hi”

    

    defaultField = native.newTextField( 10, 30, 180, tHeight )

    defaultField.font = native.newFont( native.systemFontBold, inputFontSize )

    defaultField:addEventListener( “userInput”, fieldHandler( function() return defaultField end ) ) 

    

    

    -------------------------------------------

    – *** Create native input textfields ***

    -------------------------------------------

    – Note: currently this feature works in device builds or Xcode simulator builds only (also works on Corona Mac Simulator)

    

    

    group:insert( defaultField )

    

    

    

    bkgd:addEventListener( “tap”, listener )

    group:insert( bkgd )

    group:insert( tableView )

    

end

function scene:exitScene( event )

    defaultField:removeSelf()             

     defaultField = nil

 end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “exitScene”, scene )

return scene

HELLLLLPPPPPPPPPPP

Head out to the blog and watch Rob Miracle’s most recent video tutorial on Storyboard management. I did not review the code above but I bet you will find the answers to your questions there. 

PS. Looks like an interesting project. Good luck! 

In addition, if you post to the forums in the future, please consult the guidelines here: http://www.coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/.  In particular, please use a descriptive post title (guideline #4), use code tags (guideline #9), and don’t use all caps (guideline #11).

  • Andrew

@nick,

You’re building the scene in createScene() and destroying it in exitScene().

Since createScene() is only called once (until a purge) you will have nothing when you return to the scene.

You’ve got some options:

  1. Only actually remove content in the destroyScene() callback.
  2. Create your content in willEnterScene() or enterScene()

In case it is unclear what order things are called in here are some comments:

---------------------------------------------------------------------- --    Scene Methods: -- scene:createScene( event )  - Called when the scene's view does not exist -- scene:willEnterScene( event ) -- Called BEFORE scene has moved onscreen -- scene:enterScene( event )   - Called immediately after scene has moved onscreen -- scene:exitScene( event )    - Called when scene is about to move offscreen -- scene:didExitScene( event ) - Called AFTER scene has finished moving offscreen -- scene:destroyScene( event ) - Called prior to the removal of scene's "view" (display group) -- scene:overlayBegan( event ) - Called if/when overlay scene is displayed via storyboard.showOverlay() -- scene:overlayEnded( event ) - Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() ----------------------------------------------------------------------  

 PS - Please use code formatting next time.  It’s kinda hard to read your code like it is. 

Look for the symbol that looks like this ==>     <>    in the editor.

Simply select your code and click that button.  It will nicely format the code.

Thanks!

Put this function in enterScene on every scene. This will delete the prior scene from memory so when you go back to it later, it will reload from scratch. I’ve never really found an advantage to keeping scenes in memory, unless they use a lot of textures and take a long time to load.

Alternatives for something that pops up on screen and then you return to where you came from is to show the scene as an overlay, or put it all in a display group in the same scene and hide the group off screen until it’s needed.

[lua]

    local ready = function()            – delete the previous scene after short delay

        local previous = storyboard.getPrevious()

        if previous ~= “main” and previous then

            storyboard.removeScene(previous)

        end

    end

    timer.performWithDelay(500, ready)

[/lua]

Thank you guys!!!

Head out to the blog and watch Rob Miracle’s most recent video tutorial on Storyboard management. I did not review the code above but I bet you will find the answers to your questions there. 

PS. Looks like an interesting project. Good luck! 

In addition, if you post to the forums in the future, please consult the guidelines here: http://www.coronalabs.com/blog/2013/04/02/corona-forum-rules-and-guidelines/.  In particular, please use a descriptive post title (guideline #4), use code tags (guideline #9), and don’t use all caps (guideline #11).

  • Andrew

@nick,

You’re building the scene in createScene() and destroying it in exitScene().

Since createScene() is only called once (until a purge) you will have nothing when you return to the scene.

You’ve got some options:

  1. Only actually remove content in the destroyScene() callback.
  2. Create your content in willEnterScene() or enterScene()

In case it is unclear what order things are called in here are some comments:

---------------------------------------------------------------------- --&nbsp;&nbsp;&nbsp;&nbsp;Scene Methods: -- scene:createScene( event ) &nbsp;- Called when the scene's view does not exist -- scene:willEnterScene( event ) -- Called BEFORE scene has moved onscreen -- scene:enterScene( event ) &nbsp; - Called immediately after scene has moved onscreen -- scene:exitScene( event ) &nbsp; &nbsp;- Called when scene is about to move offscreen -- scene:didExitScene( event ) - Called AFTER scene has finished moving offscreen -- scene:destroyScene( event ) - Called prior to the removal of scene's "view" (display group) -- scene:overlayBegan( event ) - Called if/when overlay scene is displayed via storyboard.showOverlay() -- scene:overlayEnded( event ) - Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() ---------------------------------------------------------------------- &nbsp;

 PS - Please use code formatting next time.  It’s kinda hard to read your code like it is. 

Look for the symbol that looks like this ==>     <>    in the editor.

Simply select your code and click that button.  It will nicely format the code.

Thanks!

Put this function in enterScene on every scene. This will delete the prior scene from memory so when you go back to it later, it will reload from scratch. I’ve never really found an advantage to keeping scenes in memory, unless they use a lot of textures and take a long time to load.

Alternatives for something that pops up on screen and then you return to where you came from is to show the scene as an overlay, or put it all in a display group in the same scene and hide the group off screen until it’s needed.

[lua]

    local ready = function()            – delete the previous scene after short delay

        local previous = storyboard.getPrevious()

        if previous ~= “main” and previous then

            storyboard.removeScene(previous)

        end

    end

    timer.performWithDelay(500, ready)

[/lua]

Thank you guys!!!