Hey guys,
Really weird bug. I’ve got a table view widget going. I’m adding image and text objects to each row. But when I scroll down and scroll back up, the rows that were pushed up and off the screen will be missing some of their display objects. I’ve narrowed it down to a particular function, if the image is declared outside of the function, it’ll reappear when the rows snap back. But if it’s in the function, it disappears when the rows snap back.
I need the function to determine if the image should be added or not (there’s a db of images and it’s listing each image from the db, so it’s checking if there’s an image to be added - line 36, “if imageCounter <= (numberOfImages ) then…”). Unfortunately this seems to be the widget breaking function.
If I just add stuff in without regard to the database, it works fine. I can pull images from the database and list them out fine in the tableView, but once I do they disappear permanently when they are scrolled off screen.
It’s driving me crazy! Any help would be appreciated. I think it’s similar to this guys issue, but I couldn’t get his fix to work for me, and there were no other suggestions: https://forums.coronalabs.com/topic/58464-tableview-row-content-disappearing-when-scrolling-intermittent/
Thanks in advance for any help!!!
Here’s the code sliced out of my project (so it might not run as-is)
----------------BEGIN TABLE VIEW WIDGET--------------- local widget = require( "widget" ) -- local rowNumber = 0; --this is what is created in a row function onRowRender( event ) -- Get reference to the row group local row = event.row --get row number rowNumber = row.index; -- local rowHeight = row.contentHeight local rowWidth = row.contentWidth -- local image1 = display.newImageRect(row, "images/shelf.png",968,138); image1:scale( .50, .5 ) image1.anchorX = 0; image1.anchorY = 0; image1.x = 0+offset; image1.y = 150; -- local rowText = display.newText(row,"Row #"..rowNumber, 0, 0, \_font, 24); rowText:setTextColor(0) rowText.anchorX = 0; rowText.anchorY = 0; rowText.x =0+offset; rowText.y =150; -- local numberOfImages = 20 numberOfRowsForAllImages = 7 imageDisplayTable = {} -- if rowNumber \<= numberOfRowsForAllImages then --placing 3 images on the shelf for j = 1,3,1 do if imageCounter \<= (numberOfImages ) then --retrieve row data local rowDataTable = retrieveRow(imageCounter) -- imageDisplayTable[imageCounter] = display.newImageRect(row, "images/"..rowDataTable[4]..".png",138,200); imageDisplayTable[imageCounter].id = imageCounter imageDisplayTable[imageCounter]:scale( .7, .7 ) imageDisplayTable[imageCounter].x = 80+(150\*j); imageDisplayTable[imageCounter].y = 110; imageDisplayTable[imageCounter]:addEventListener( "touch", onObjectTouch ) -- imageCounter = imageCounter + 1; end end end -- end numberOfShelves = 6; -- function createTableView() -- Create the widget tableView = widget.newTableView { left = -84, top = 160, height = 680, width = 768, bottomPadding = 240, onRowRender = onRowRender, onRowTouch = onRowTouch, listener = scrollListener, backgroundColor = { default = { 0,0,0, 0 }}, noLines = true, hideBackground = true, } function insertAllTableViewRows() print("in insertAllTableViewRows function") -- for i = 1, numberOfShelves do -- tableView:insertRow{ rowHeight = 200, rowColor = { default = { 255,0,0, 0.0 }}, } end -- end insertAllTableViewRows() -- pageGroup:insert(tableView) end createTableView()