[Resolved] display.loadRemoteImage in tableview

Have you upgraded to daily build 1034 or later? Those builds include widgets 2.0 and how you access the rows has changed. Please make sure that you download the latest documents to go with 1034 or 1035 and read the migration guide.
[import]uid: 199310 topic_id: 33379 reply_id: 144189[/import]

Thanks for your answer. I am aware of widget 2.0, but the app I am developing is in it’s final stage and I cannot afford to migrate just yet (right now I do not want to find myself immerse in other issues in case they appear on migration). My client expects to have the app released asap and will have to migrate in next version. [import]uid: 168845 topic_id: 33379 reply_id: 144201[/import]

The reason I asked is the way row groups are done in 2.0 is different.

The way Lua scopes variables, both rowBG and rowGroup are available inside of your call back function.

If that listener function was outside of your rowRender function, then it would not be. There has to be something else going on. I don’t know how many rows you’re dealing with and if this happens while scrolling the list, but one of the issues with widgets 1.0 is that as rows scroll out of view, they are deleted. If that listener call back fires and that that row has been removed (to save memory), you will get things like rowGroup being nil.

I had to put in several tests to see if those were nil and just return since that row doesn’t really exist anyway.

Does this describe the behavior? Or is this happening with a row that is on screen? [import]uid: 199310 topic_id: 33379 reply_id: 144209[/import]

I am trying to make a loadRemoteImage work inside a TableView and I can’t get it to work. I’d rather not have the row group as global but cannot seem to get the row group or any previous declared variable accepted inside the listener of the loadremoteimage.

here is the code I try:

local function onEventsListRowRender( event )  
 local rowGroup = event.view  
 local row = event.target  
 local index = event.index  
 local eventid = event.id  
 local eventData = data.loadEventFromDB(eventid)  
 local imagename, imagetype = data.searchProfileAvatar(eventData.profile\_id);  
 local eventImage;  
  
 local rowBG = display.newRect(rowGroup, 6, 4, \_W-12, 82);  
 rowBG:setFillColor(255,255,255)  
 rowBG.strokeWidth = 1;  
 rowBG:setStrokeColor(180,180,180)  
  
 local function networkLoadRemoteImageListener( event )  
 eventImage = event.target   
 if ( event.isError ) then  
 print ( "Network error - download failed" )  
 else   
 eventImage.width = 75  
 eventImage.height = 75  
 eventImage:setReferencePoint(display.CenterLeftReferencePoint);  
 eventImage.x = 10;  
 eventImage.y = rowBG.y;  
 eventImage.alpha=0;  
 transition.to( eventImage, { alpha = 1.0 } )  
 rowGroup:insert(eventImage)  
 end  
 end  
 local remoteimageurl = "http://myurl/"..imagetype.."/"..imagename;  
 display.loadRemoteImage( remoteimageurl, "GET", networkLoadRemoteImageListener, imagename, system.CachesDirectory, 75, 75 )  
end  

And I keep getting
WARNING: Attempting to set property(y) with nil Error: attempt to call method ‘insert’ (a nil value)
Any ideas on how this should work? Can’t seem to find any documentation or examples. Thanks in advance [import]uid: 168845 topic_id: 33379 reply_id: 144184[/import]

Have you upgraded to daily build 1034 or later? Those builds include widgets 2.0 and how you access the rows has changed. Please make sure that you download the latest documents to go with 1034 or 1035 and read the migration guide.
[import]uid: 199310 topic_id: 33379 reply_id: 144189[/import]

Thanks for your answer. I am aware of widget 2.0, but the app I am developing is in it’s final stage and I cannot afford to migrate just yet (right now I do not want to find myself immerse in other issues in case they appear on migration). My client expects to have the app released asap and will have to migrate in next version. [import]uid: 168845 topic_id: 33379 reply_id: 144201[/import]

The reason I asked is the way row groups are done in 2.0 is different.

The way Lua scopes variables, both rowBG and rowGroup are available inside of your call back function.

If that listener function was outside of your rowRender function, then it would not be. There has to be something else going on. I don’t know how many rows you’re dealing with and if this happens while scrolling the list, but one of the issues with widgets 1.0 is that as rows scroll out of view, they are deleted. If that listener call back fires and that that row has been removed (to save memory), you will get things like rowGroup being nil.

I had to put in several tests to see if those were nil and just return since that row doesn’t really exist anyway.

Does this describe the behavior? Or is this happening with a row that is on screen? [import]uid: 199310 topic_id: 33379 reply_id: 144209[/import]

Hi~~~   i have problems about insert many images (obtained by  display.loadRemoteImage ) in tableview  :frowning:

I want to download and show  images in onRowRender function but when i slip slightly the image in the corresponding line will disappeared or not(i dont know the reason···)

 

The following code is my code

 

local filename={} local news = {} news[1] = {} news[1].url = "http://www.1000eyes.com/img/1/1/4/2013031510000004\_2.jpg" news[2] = {} news[2].url = "http://www.1000eyes.com/img/1/1/1/2013031510000002\_2.jpg" news[3] = {} news[3].url = "http://www.1000eyes.com/img/1/1/45/2013031510000010\_2.jpg" news[4] = {} news[4].url = "http://www.1000eyes.com/img/1/1/58/2013031510000009\_2.jpg" local listOptions = { top = 200, left = 0, width = display.contentWidth, height = 600, bgColor = {50,50,100} } --list myList = widget.newTableView( listOptions ) -- onRender listener for the tableView local function onRowRender( event ) local row = event.target local rowGroup = event.view index = event.index filename[index] = event.index local function networkListener( event ) if ( event.isError ) then print ( "Network error - download failed" ) else local img = event.target rowGroup:insert(img) end end display.loadRemoteImage( news[event.index].url, "GET", networkListener, filename[event.index] .. ".png", system.DocumentsDirectory, 0, 0 ) end local mask1 = display.newRect(0,0,display.contentWidth,200) mask1:setFillColor(255,0,0) local mask2 = display.newRect(0,listOptions.top + listOptions.height,display.contentWidth,500) mask2:setFillColor(0,255,0) for i=1, #news do myList:insertRow{ id = i, onRender = onRowRender, height = 300 } weburl = news[i] end

 

Thanks

@gnguoning, what build of Corona are you using?

Trial build 971

 

Hi ,  Rob i am a new user of Corona ~~~

So is there logical or syntax error in code? :wacko:

 

Thanks!!!

Are you getting any errors printed in your terminal?  I don’t see any obvious errors.  

No , no error

 

And the following picture show  the display error in simulator

 

when i slip slightly between image3 and image4  the image3 are disappeared

You seem to be setting a custom height of 600 px for the table view.  If you are not using the full screen, you need to create a mask file and apply it to get things to display right.  Try taking out the height = 600 for now and see if changes anything.

But Rob, I modify the code but new error occurred

 

widget = require "widget" local bg = display.newRect(0,0,display.contentWidth,display.contentHeight) bg:setFillColor(100,100,0) local listOptions = { top = 100, left = 0, width = display.contentWidth, height = 180\*2,--600, bgColor = {50,50,100} } myList = widget.newTableView( listOptions ) -- onRender listener for the tableView local function onRowRender( event ) local row = event.target local rowGroup = event.view local rowW = row.width local rowH = row.height index = event.index local function networkListener( event1 ) if ( event.isError ) then print ( "Network error - download failed" ) else event1.target:setReferencePoint(CenterReferencePoint) event1.target.width = 160 event1.target.height = 160 rowGroup:insert(event1.target) end end display.loadRemoteImage( "http://developer.anscamobile.com/demo/hello.png", "GET", networkListener, "helloCopy"..index..".png", system.TemporaryDirectory, 0, 0 ) end for i=1, 5 do myList:insertRow{ id = i, onRender = onRowRender, height = 180--300 } end --top mask fo list local masktop = display.newRect(0,0,display.contentWidth,listOptions.top) masktop:setFillColor(255,255,255) --bottom mask local maskbottom = display.newRect(0,listOptions.top + listOptions.height,display.contentWidth,180) maskbottom:setFillColor(255,255,255)

When i  scroll from top to bottom (or from bottom to top) largely there will be error as below:

 

Runtime error (line 33)

attempt to call method “insert”    (a nil value)  

what is line 33?

rowGroup:insert(event1.target)   ——  this  line

 

 

when i insert image in rowGroup (the  “event.view”  ) 

rowGroup.insert has become nil instead of being a function.  This is likely a row that has scrolled off the screen that the downloader is trying to access.

 

Do this:

 

[lua]

   if rowGroup and rowGroup.insert then

         rowGroup:insert(event1.target)

   end

[/lua]

and see if that helps

Thanks Rob  :slight_smile:

Yes that  works  

 

But like you said   when   downloader  trying to access  happened  after scrolling off the screen , the corresponding  image will stay in screen all the time ~~~~~~

then add an “else” clause that removes event1.target.

 

Unfortunately  the error also occurred  :frowning:

 

 

 

I add the following code 

 

 

if rowGroup and rowGroup.insert then

      rowGroup:insert(event1.target)

else

      event1.target:removeSelf()

      event1.target =nil

  end