onRowRender event not calling in a nested loop

I have a scene that utilizes a tableview list. I populate the tableview with tableView:insertRow function, which should call the onRowRender function to render the row. This code works:

Note: tableView:insertRow is in a nested loop embedded within a nested loop (For then If)

for i = 1, #nameData do idx=idx+1 local isCategory = false local rowHeight = 67 -- 67, 84 local rowColor = { default = { 1, 1, 1 }, } local lineColor = { 220/255, 220/255, 200/255 } if lastCat ~= nameData[i].category then lastCat = nameData[i].category idx2=0 tableView:insertRow( { isCategory = true, rowHeight = 24, rowColor = { default = { 150/255, 160/255, 180/255 } }, lineColor = lineColor, params = {idx = idx} }) else idx2=idx2+1 print (idx2) print (nameData[idx][idx2].provider) paramoptions ={ idx=idx, idx2=idx2 } tableView:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor, params = {paramoptions} }) end end

This code does not. Specifically, the onRowRender function doesn’t get called. The pointer just goes back to the top of the loop and never calls onRowRender. The only difference is that the tableView:insertRow is embedded one level deeper (For then For then If). 

for i = 1, #nameData do idx=idx+1 for d=1, #nameData[i] do local isCategory = false local rowHeight = 67 -- 67, 84 local rowColor = { default = { 1, 1, 1 }, } local lineColor = { 220/255, 220/255, 200/255 } if lastCat ~= nameData[i].category then lastCat = nameData[i].category idx2=0 tableView:insertRow( { isCategory = true, rowHeight = 24, rowColor = { default = { 150/255, 160/255, 180/255 } }, lineColor = lineColor, params = {idx = idx} }) else idx2=idx2+1 print (idx2) print (nameData[idx][idx2].provider) paramoptions ={ idx=idx, idx2=idx2 } tableView:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor, params = {paramoptions} }) end end end

Greatly appreciate any suggestions or insights as to why the first version calls the onRowRender but the second doesn’t?

Thanks!

Just to qualify, while the first example does work, it doesn’t achieve the end result due to the structure of the data which contains a table inside a table. ([category1,{item1,item2,item3}],[category2,{item1,item2}])

Any takers?

onRowRender is only called when the row is actually displayed on the screen.  It’s not called as part of the loop.  When you move the tableView to bring a row on the screen, it’s onRowRender() will be called.

Rob

Thanks for the explanation. For others viewing this post this article gives a clear explanation…

http://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/

Just to qualify, while the first example does work, it doesn’t achieve the end result due to the structure of the data which contains a table inside a table. ([category1,{item1,item2,item3}],[category2,{item1,item2}])

Any takers?

onRowRender is only called when the row is actually displayed on the screen.  It’s not called as part of the loop.  When you move the tableView to bring a row on the screen, it’s onRowRender() will be called.

Rob

Thanks for the explanation. For others viewing this post this article gives a clear explanation…

http://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/