I need help in TableView widget when using event.view in the onRowRender function ?

Hi team,

I am struggling with this error when I am doing function onRowRender for the Tableview widget " attempt to index local ‘rowGroup’ (a nil value) stack traceback:" 

the code issue error when I am using rowGroup. when I removed it, the code works fine. What is wrong in event.view ??

any help

[lua]

function onRowRender( event )
  

  local row = event.row
  local rowGroup = event.view

  local idx = row.index or 0
  local color = 0

  --print(“test”)

  row.textObj = display.newText(row, “Row #” … idx, 0, 0, “Helvetica”, 18 )
  row.textObj:setTextColor( color )
  row.textObj:setReferencePoint( display.CenterLeftReferencePoint )
  row.textObj.x = 20
  row.textObj.y = rowGroup.contentHeight * 0.35
 

  rowGroup:insert(row.textObj)
  
 end – onRowRender

[/lua]

Any particular reason you wish to use rowGroup? I think if you edit your code as follows it should work. Apologies if I’m missing something here. 

function onRowRender( event ) local row = event.row local idx = row.index or 0 local color = 0 --print("test") local textObj = display.newText(row, "Row #" .. idx, 0, 0, "Helvetica", 18 ) textObj:setTextColor( color ) textObj:setReferencePoint( display.CenterLeftReferencePoint ) --G1 compatibility mode required textObj.x = 20 textObj.y = row.contentHeight \* 0.35 end -- onRowRender

Thanks ksan for the quick response. I need to use that rowGroup to do insert as well so we dont full the memory later on. As I read in some articles it is good practice to handle it this way. I am not sure if there another way do insert in a group and purge them later. Thx Abdul

You’re most welcome. My understanding is (and I might very well be wrong…) is that this should work well. When you use the following to insert text into your row : 

local textObj = display.newText(row, “Row #” … idx, 0, 0, “Helvetica”, 18 )

You are actually telling the SDK that the new textObject will be inserted into the group called row which earlier in the code you define as local row = event.row. So any display object inserted in this manner becomes part of the row. The rows and their contents are managed by the tableView widget and you don’t need to worry about removing them later on individually. Tableview widget will do as needed and remove them for you when the time comes. 

Hope this helps. Regards,

Kerem

Great :slight_smile: Thanks sir for the quick help … Regards Abul

You’re most welcome. Good luck with your project.

Any particular reason you wish to use rowGroup? I think if you edit your code as follows it should work. Apologies if I’m missing something here. 

function onRowRender( event ) local row = event.row local idx = row.index or 0 local color = 0 --print("test") local textObj = display.newText(row, "Row #" .. idx, 0, 0, "Helvetica", 18 ) textObj:setTextColor( color ) textObj:setReferencePoint( display.CenterLeftReferencePoint ) --G1 compatibility mode required textObj.x = 20 textObj.y = row.contentHeight \* 0.35 end -- onRowRender

Thanks ksan for the quick response. I need to use that rowGroup to do insert as well so we dont full the memory later on. As I read in some articles it is good practice to handle it this way. I am not sure if there another way do insert in a group and purge them later. Thx Abdul

You’re most welcome. My understanding is (and I might very well be wrong…) is that this should work well. When you use the following to insert text into your row : 

local textObj = display.newText(row, “Row #” … idx, 0, 0, “Helvetica”, 18 )

You are actually telling the SDK that the new textObject will be inserted into the group called row which earlier in the code you define as local row = event.row. So any display object inserted in this manner becomes part of the row. The rows and their contents are managed by the tableView widget and you don’t need to worry about removing them later on individually. Tableview widget will do as needed and remove them for you when the time comes. 

Hope this helps. Regards,

Kerem

Great :slight_smile: Thanks sir for the quick help … Regards Abul

You’re most welcome. Good luck with your project.