The behavior is unpredictable. Run the following code. The code is trying to set the category name for every 10th row. Scroll up and down and you will observe that sometimes, param is passed even when it is a category row. Sometimes it isn’t passed.
Basically, I am trying to setup the text for category row. Any suggestions would be much appreciated.
[lua]–
local widget = require( “widget” )
– hide device status bar
display.setStatusBar( display.HiddenStatusBar )
function onRowRender(event)
local t = nil
if (event.row.params == nil) then
t = event.target.categoryName
else
t = “” … event.row.params.text
end
local myText = display.newText(
event.row,
t,
100,
10,
native.systemFont,
16 )
myText:setFillColor( 1, 0, 0 )
end
local tableView = widget.newTableView
{
left = 0,
top = 20,
height = display.contentHeight,
width = display.contentWidth,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
listener = scrollListener,
noLines = true
}
– Insert 40 rows
for i = 1, 40 do
local isCategory = false
local rowHeight = 36
local rowColor = { default={ 1, 1, 1 }, over={ 1, 0.5, 0, 0.2 } }
local lineColor = { 0.5, 0.5, 0.5 }
tableView.categoryName = "Category " … i
– Make some rows categories
if ( i % 10 == 0 ) then
isCategory = true
rowHeight = 40
rowColor = { default={ 0.8, 0.8, 0.8, 0.8 } }
lineColor = { 1, 0, 0 }
end
– Insert a row into the tableView
tableView:insertRow(
{
isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
params = { text = “Row” … i }
}
)
end[/lua]