This is a question about understanding what is going on. I do know how to get the result I require.
In the attached code, if line 27 ( row.insert(row.bg) ) is commented out, the first row only of the table gets overlaid with the background cover. If line 27 is included, everything works as I would expect. My questions:
-
Why does the row background get inserted at all without a _row.inser_t statement
-
Why does it appear on top of the text ?
-
Given that it does get inserted, why only on the first iteration of the insertRow loop?
[lua]
widget = require “widget”
_CH = display.contentHeight
_CW = display.contentWidth
local t = {}
t = {
{ name = “row1”, data = “data1”} ,
{ name = “row2”, data = “data2”} ,
{ name = “row3”, dta = “data3”} ,
}
local function onRowRender(event)
local row = event.row
local rowHeight = row.contentHeight
row.bg = display.newRect(0, 0, _CW, rowHeight)
row.bg.anchorX = 0
row.bg.anchorY = 0
row.bg:setFillColor(1, 0.5, 1, 0.5)
– without the next statement - the 1st row is overlaid with row.bg
– row:insert(row.bg)
row.nameText = display.newText(
row, row.params.name, 20 , 0, nil, 12)
row.nameText.anchorX =0
row.nameText.x = 10 ; row.nameText.y = rowHeight/2
row.nameText:setFillColor(0)
end
local tableView = widget.newTableView {
height = _CH/2 ,
onRowRender = onRowRender
}
– insert data
for i = 1, 3 do
tableView:insertRow {
rowHeight= 50 ,
params = {
name = t[i].name
}
}
end
[/lua]