Reusing rows in display.newTableView()

Hello everybody,

I am having some performance issues using a newTableView with a rather complex row.

Instead of redrawing every time the row in “onRowRender” method I am trying to reuse rows. I would like to keep the row as rendered the first time even if it goes off screen.

I have tryied something like this (where createRow returns a display group):

local function onRowRender( event ) local row = event.row if (row.group == nil) then row.group = rightMenu.createRow(row) end row:insert(row.group) end

Every time the onRowRender is called the row.group property is nil and the row is redrawn.

I also tryed adding the group to row.params.group, but as soon as the rows goes off screen the display group is removed. row.params.group is not nil, but emptied and there only remains removeSelf function.

I have also tryed to insert the row display groups in an external array, but the behaviour is the same as using row.params.group

Is there a way to achieve what I am trying to do? Am I missing something?

Thank you,

Francesco

If you don’t want to use the destroy-create feature of tableView, have you considered using a scrollView instead?

Hello memo,

thank you for your reply.

I know that I can use newScrollView, but I would like to continue using newTableView for a few reasons: category headers, the presence of onRowTouch and onRowRender, the ability to manage rows and to call reloadData to force the redraw of all the rows…

And I would like to be able to implement my own login in onRowRender to choose when to redraw and when not.

I will fall back on newScrollView eventually.

Thank you,

Francesco Comi

Ok, that makes sense, implementing category rows manually would indeed be quite a hassle. I assume when the row scrolls out of scope, display.remove(row) is called, which would remove any display objects you had in the row, regardless of whether you keep some separate reference to them. I can think of two workarounds, but sadly neither of them are elegant:

  • Listen to the scroll event. Move the display objects from the row to another display group just before they are destroyed, then move them back in onRowRender()

  • Never actually insert the objects into the row, but have them in a separate display group. When the row is onscreen, use an enterFrame listener to align their x,y coordinates with the (empty) row. When the row goes offscreen, put the row contents somewhere offscreen too.

That’s all I can think of, maybe someone has a better idea.

Yes, I could try to listen for the scroll event to detect when a row goes off screen and move its display group.

…this is not what i was hoping for.

Thank you,

Francesco

If you don’t want to use the destroy-create feature of tableView, have you considered using a scrollView instead?

Hello memo,

thank you for your reply.

I know that I can use newScrollView, but I would like to continue using newTableView for a few reasons: category headers, the presence of onRowTouch and onRowRender, the ability to manage rows and to call reloadData to force the redraw of all the rows…

And I would like to be able to implement my own login in onRowRender to choose when to redraw and when not.

I will fall back on newScrollView eventually.

Thank you,

Francesco Comi

Ok, that makes sense, implementing category rows manually would indeed be quite a hassle. I assume when the row scrolls out of scope, display.remove(row) is called, which would remove any display objects you had in the row, regardless of whether you keep some separate reference to them. I can think of two workarounds, but sadly neither of them are elegant:

  • Listen to the scroll event. Move the display objects from the row to another display group just before they are destroyed, then move them back in onRowRender()

  • Never actually insert the objects into the row, but have them in a separate display group. When the row is onscreen, use an enterFrame listener to align their x,y coordinates with the (empty) row. When the row goes offscreen, put the row contents somewhere offscreen too.

That’s all I can think of, maybe someone has a better idea.

Yes, I could try to listen for the scroll event to detect when a row goes off screen and move its display group.

…this is not what i was hoping for.

Thank you,

Francesco