thank you for answering Richard9
I have posted my code for my table in enterScene() and beneath this my code fro inserting data. They are both in separate lua files.
I have only worked with Corona since January and is quite new to programming, so I have tried but with out luck to write a function for updating the table. Do I have to insert the whole table once more? I’m not sure how I can write the function for updating the table.
EnterScene code:
[code]
–
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
widget.setTheme( “theme_ios” )
local sqlite = require “sqlite3”
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
local path = system.pathForFile( “colordata.db”, system.DocumentsDirectory )
local db = sqlite3.open( path )
local tablesetup = [[CREATE TABLE IF NOT EXISTS list (id INTEGER PRIMARY KEY autoincrement, name, producer);]]
–db:exec( tablesetup )
local listOptions = {
top = 60,
width= 320,
height = 366,
maskFile = “mask-410.png”
}
local list = widget.newTableView (listOptions)
for row in db:nrows[[SELECT * FROM list]] do
local producer = row.producer
local name = row.name
local function onRowTouch( event )
local row = event.row
local text = rowtextObj
local background = event.background
if event.phase == “press” then
print( "Pressed row: " … event.index )
background:setFillColor( 255, 255, 255, 255 )
if row.textObj then
row.textObj:setReferencePoint( display.TopLeftReferencePoint )
row.textObj.x = 20
end
elseif event.phase == “release” or event.phase == “tap” then
print( "Tapped and/or Released row: " … event.index )
background:setFillColor( 0, 110, 233, 255 )
row.reRender = true
– set chosen row index to this row’s index
producerP = producer
nameP = name
– go to row scene
storyboard.gotoScene( “colorPage”, “slideLeft”, 350 )
end
end
– function below handles row rendering
local function onRowRender( event )
local group = event.view
local row = event.target
local index = event.index
local id = event.id
local bg = display.newImageRect(“rowBgNew.png”, 320, 40)
bg:setReferencePoint( display.CenterReferencePoint )
bg.x = row.width * 0.5
bg.y = row.height * 0.5
local text = display.newText( name… ", "…producer, 0, 0, native.systemFont, 12)
text:setReferencePoint( display.CenterLeftReferencePoint )
text:setTextColor(76, 48, 30 )
text.x = 25
text.y = row.height * 0.5
group:insert( bg )
group:insert( text )
row.textObj = text
end
list:insertRow{
–id = "unique-row " …i,
onRender=onRowRender,
listener = onRowTouch,
height = 39
}
end
group:insert( list )
–tab bar
local sbHeight = display.statusBarHeight
local tbHeight = 44
local top = sbHeight + tbHeight
–top bar
local titleBar = widget.newTabBar{
top = sbHeight,
background = “navBarNew.png”,
height = 44
}
group:insert( titleBar )
local shadow = display.newImage( “assets/shadow.png” )
shadow:setReferencePoint( display.TopLeftReferencePoint)
shadow.x, shadow.y = 0, top
shadow.xScale = 320 / shadow.contentWidth
shadow.alpha = 0,45
group:insert( shadow )
local titleTextPigment = display.newImage(“colorTitel.png”)
titleTextPigment.x = 160
titleTextPigment.y = titleBar.y
group:insert( titleTextPigment)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
end
function scene:destoryScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, widgets, save state, 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 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
[code]
Insert Data scene:
[code]
–
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene(pigmentList)
local widget = require “widget”
widget.setTheme( “theme_ios” )
local sqlite = require “sqlite3”
local titel1
local addColorButton
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
local testText
local titleTextPigment
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local path = system.pathForFile(“colordata.db”, system.DocumentsDirectory)
db = sqlite3.open( path )
print(path)
–add function for button add color eller save
local addColor_function = function ( event )
if event.phase == “release” then
– save color data to database
local tablefill =“INSERT INTO list VALUES (NULL,’” … name.text … “’,’” … producer.text … “’);”
print(tablefill)
db:exec( tablefill )
–return to color list
native.setKeyboardFocus( nil )
storyboard.gotoScene( “favorit”, “slideRight”, 350 )
storyboard.removeScene( “pigmentList” )
end
end
–objects
local bkg = display.newImage( “bkg.png” )
bkg:setReferencePoint( display.CenterReferencePoint )
bkg.x = 160
bkg.y = 240
group:insert( bkg )
addColorButton = widget.newButton {
label = “Add Color”,
onEvent = addColor_function
}
addColorButton.x = 160
addColorButton.y = 120
group:insert(addColorButton)
titel1 = display.newEmbossedText( “ADD A COLOR”, 0 , 0, native.systemFontBold, 20 )
titel1:setTextColor( 0 )
titel1:setReferencePoint( display.CenterReferencePoint )
titel1.x, titel1.y = 160 , 80
titel1.isVisible = true
group:insert( titel1 )
– textboxes and labels
local nameLabel = display.newText(“Name:”, 20, 155, native.systemFontBold, 12)
nameLabel:setTextColor(0)
group: insert(nameLabel)
name = native.newTextField(100, 155, 150, 22)
name.inputType=“default”
name.isVisible = true
local producerLabel = display.newText(“Producer:”, 20, 180, native.systemFontBold, 12 )
producerLabel:setTextColor(0)
group: insert(producerLabel)
producer = native.newTextField(100, 180, 150, 22)
producer.inputType=“default”
producer.isVisible = true
–staus bar
local sbHeight = display.statusBarHeight
local tbHeight = 44
local top = sbHeight + tbHeight
–top bar
local titleBar = widget.newTabBar{
top = sbHeight,
background = “navBarNew.png”,
height = 44
}
group:insert( titleBar )
local shadow = display.newImage( “assets/shadow.png” )
shadow:setReferencePoint( display.TopLeftReferencePoint)
shadow.x, shadow.y = 0, top
shadow.xScale = 320 / shadow.contentWidth
shadow.alpha = 0,45
group:insert( shadow )
local titleTextPigment = display.newImage(“pigmentTitel.png”)
titleTextPigment.x = 160
titleTextPigment.y = titleBar.y
group:insert( titleTextPigment)
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
if name then
name.isVisible = true
end
if producer then
producer.isVisible = true
end
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
if name then
name.isVisible = false
end
if producer then
producer.isVisible = false
end
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
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 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
[code] [import]uid: 119838 topic_id: 25422 reply_id: 102793[/import]