newTableView asynchronous lazy loading with loadRemoteImage()

I’ve been having a problem with images being loaded with loadRemoteImage in newTableViews.  The issue i’m having is I’m seeing images being added to the default display group vs the the table row.  I’m assuming this is because the table row group is not valid and it fall back to the default display group.

I’m thinking this is related to the asynchronous lazy loading of the newTableViews.  The on rowRender on my table will load a remote image and cache it.  If I zip down to the bottom of my table, which forces the lazyLoadng of a new/last row, and zip to the top so that row is no longer in focus, the image that was supposed to be placed in that row gets added to the default group vs the table row group.  The result is an image that fills up the screen and overlays the tableview.  It looks like the event listener for loadRemoteImage is being called after the row lost focus.

I’ve added checks to see if the row/group is null before adding in both the rowRender and loadRemoteImage listeners, but it doesn’t look like the group is actually nil.

Does the newTableView free memory by removing rows that are not visible on the screen?  If/when this happens, is there a way for the listener of the loadRemoteImage to know that the row is no longer available and call :removeSelf() on the image so it doesn’t get added?

I checked out the github code (https://github.com/coronalabs/framework-widget/blob/master/widgetLibrary/widget_tableview.lua)

I see the code around line 892

if not isRowWithinBounds then -- Remove this row display.remove( currentRow.\_view ) currentRow.\_view = nil end

looks straight forward.  So when i’m in my onRowRender function and looking at the event.row group, which points to currentRow._view, I don’t see why when I check event.row it would not return nil after i’m out of bounds.  

I must be missing something simple.

 

In case anyone else has a similar issue, the work around i came up with was to check for event.row._proxy before trying to add an image to the row.  Otherwise you’ll get a message about "attempting to call method ‘insert’ <a nil value>’.   Checking for event.row~=nil will not work.   I compared the tables for event.row when the row was in and out of bounds…  I noticed _cell was an empty table and _proxy element was missing.

So my code looks like

local function onRowRender(event) .... display.loadRemoteImage( photo\_url, "GET", function(lri\_event) --Check if row is in bounds by looking for existence of \_proxy if(event.row.\_proxy ) then if(lri\_event.isError) then print("----error loading photo") else --image is saved in lri\_event.target ..... event.row:insert(lri\_event.target) end else --Do not add image to row, it is out of bounds display.remove(lri\_event.target) end end, "cache/" .. photo\_name , system.TemporaryDirectory ) .... end

I checked out the github code (https://github.com/coronalabs/framework-widget/blob/master/widgetLibrary/widget_tableview.lua)

I see the code around line 892

if not isRowWithinBounds then -- Remove this row display.remove( currentRow.\_view ) currentRow.\_view = nil end

looks straight forward.  So when i’m in my onRowRender function and looking at the event.row group, which points to currentRow._view, I don’t see why when I check event.row it would not return nil after i’m out of bounds.  

I must be missing something simple.

 

In case anyone else has a similar issue, the work around i came up with was to check for event.row._proxy before trying to add an image to the row.  Otherwise you’ll get a message about "attempting to call method ‘insert’ <a nil value>’.   Checking for event.row~=nil will not work.   I compared the tables for event.row when the row was in and out of bounds…  I noticed _cell was an empty table and _proxy element was missing.

So my code looks like

local function onRowRender(event) .... display.loadRemoteImage( photo\_url, "GET", function(lri\_event) --Check if row is in bounds by looking for existence of \_proxy if(event.row.\_proxy ) then if(lri\_event.isError) then print("----error loading photo") else --image is saved in lri\_event.target ..... event.row:insert(lri\_event.target) end else --Do not add image to row, it is out of bounds display.remove(lri\_event.target) end end, "cache/" .. photo\_name , system.TemporaryDirectory ) .... end