TableView Category Not Rendering Properly

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]

Just for clarity though this is not the same issue OP posted about right? It seems like a totally separate bug. Right?

I thought the original issue was the isCategory was not rendering correct values and I am hitting a very similar issue. But you are right. His issue is slightly different than mine.

The bug number I reported was for params not being passed on category rows.    Keep in mind onRowRender only gets called when the row needs to be rendered.  Category rows stick to the top while that one is on the screen, so it could give you the illusion that it works sometimes.

Rob

Try the " id" approach. It works with your code. See slight changes in your For loop as well as ORR. This works well and you can use it as an alternate to params but obviously you could not pass more than one data element which you would with params. Just for a Category title it works well though. 

-- local widget = require( "widget" ) -- hide device status bar display.setStatusBar( display.HiddenStatusBar ) function onRowRender(event) local t = nil if event.row.isCategory then t = event.row.id else t = "" .. event.row.params.text end --[[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 } local idText = "" --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 } idText = "Category " .. i end -- Insert a row into the tableView tableView:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor, id = idText, params = { text = "Row" .. i } } ) end

ksan, thanks. This worked perfect for my use case  :slight_smile:

Great!!! You’re most welcome.

Hey guys,

This got fixed in 2013.2109.

Thanks,

alex

I tested with 2013.2109. However “params” is still null in “onRowRender” when isCategory is set to true in insertRow.

Can you kindly post some code for better understanding? Thanks much!!!

Run the following code and it will throw error saying that params is nil when isCategory is true.

[lua]–

local widget = require( “widget” )

– hide device status bar
display.setStatusBar( display.HiddenStatusBar )

function onRowRender(event)
local myText = display.newText(
event.row,
event.row.params.text,
100,
10,
native.systemFont,
16 )
myText:setFillColor( 1, 0, 0 )
end

local tableView = widget.newTableView
{
left = 0,
top = 0,
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 }

– Make some rows categories
if ( i == 1 or i == 21 ) 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]

This is a known bug: 27439.  You can check to see if params is nil before trying to access it to keep it from crashing, but you should be allowed send params to category rows as well.

Rob

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]

Just for clarity though this is not the same issue OP posted about right? It seems like a totally separate bug. Right?

I thought the original issue was the isCategory was not rendering correct values and I am hitting a very similar issue. But you are right. His issue is slightly different than mine.

The bug number I reported was for params not being passed on category rows.    Keep in mind onRowRender only gets called when the row needs to be rendered.  Category rows stick to the top while that one is on the screen, so it could give you the illusion that it works sometimes.

Rob

Try the " id" approach. It works with your code. See slight changes in your For loop as well as ORR. This works well and you can use it as an alternate to params but obviously you could not pass more than one data element which you would with params. Just for a Category title it works well though. 

-- local widget = require( "widget" ) -- hide device status bar display.setStatusBar( display.HiddenStatusBar ) function onRowRender(event) local t = nil if event.row.isCategory then t = event.row.id else t = "" .. event.row.params.text end --[[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 } local idText = "" --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 } idText = "Category " .. i end -- Insert a row into the tableView tableView:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor, id = idText, params = { text = "Row" .. i } } ) end

ksan, thanks. This worked perfect for my use case  :slight_smile:

Great!!! You’re most welcome.