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