After upgrading to the latest build a few of my routings stopped working - so I re-wrote them. I’m stuck now passing the record results to onRowRender.
I’ve got it working but I think it’s klugey - I create a var called pass_row. Then as I loop through the database records I set pass_row = to row, then use pass_row.xxxx in the onRowRender function.
There must be a more elegant way to do this, isn’t there ?
Or should I somehow restructure what I’m doing ?
The goal is to read rows from an sqlite db and then present them in a table with touch events.
Thanks in advance for your suggestions,
leon …
---------------------------------------------------------------------------------
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local widget = require"widget"
-------------5--------------------------------------------------------------------
local backgroudImage, memLabel
local rowColor = { 230, 255, 255, 255 }
local rowHeight, lineColor, isCategory
local goToMainMenu = function (event)
storyboard.gotoScene(false, “mainmenu”, “fade”, 400)
return true
end
local pass_row
function scene:createScene(event)
local screenGroup = self.view
backgroundImage = display.newImage(“aojtbackground.png”)
screenGroup:insert(backgroundImage)
local onRowRender = function (event)
local row = event.row
local rowTitle = display.newText( row, "Row " … row.index … pass_row.companyname … ", " … pass_row.phone , 0, 0, nil, 14)
rowTitle.x = 40
rowTitle.y = row.contentHeight * 0.5
rowTitle:setTextColor( 0,0,0)
end
local list = widget.newTableView({
top = 70,
height = 360,
maskFile = “listmask.png”,
onRowRender = onRowRender,
}
)
screenGroup:insert(list)
function showRows(which)
list:deleteAllRows() – clear it first
for row in db:nrows(“select * from companies order by id”) do
local lineColor = {220,20,200}
tcompanyname = row.companyname
pass_row = row
list:insertRow {
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
}
print(row.id)
end
end
goBackButton = ui.newButton{
default = “backarrow.png”,
onRelease = goToMainMenu
}
goBackButton.x = 30
goBackButton.y = 20
screenGroup:insert(goBackButton)
end
function scene:enterScene(event)
– redraw the rows each time they enter
showRows()
end
function scene:exitScene()
end
function scene:destroyScene(event)
end
scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
scene:addEventListener(“destroyScene”, scene)
return scene