Thank you @primoz.cerar and @Rob.
I’m currently using daily build 2153.
When I create imageGroups inside onRowRender, it goes haywire – so I moved it outside the onRowRender function.
I put together a simple test project just for this, and the main.lua looks like this:
[lua]
display.setStatusBar( display.HiddenStatusBar )
local widget = require( “widget” )
local prod = {}
local img = {}
local txt = {}
local btn = {}
img.btnBuySheetOption = {
width = 50,
height = 24,
numFrames = 2,
sheetContentWidth = 50,
sheetContentHeight = 48
};
img.btnBuySheet = graphics.newImageSheet( “PNG/btnBuy50x24.png”, img.btnBuySheetOption )
img.prodSheetOption = {
width = 40,
height = 40,
numFrames = 25,
sheetContentWidth = 200,
sheetContentHeight = 200
};
img.prodSheetData = {
start = 1,
count = 25
};
img.prodSheet = graphics.newImageSheet( “PNG/prod1.png”, img.prodSheetOption )
local buyNow = function()
print(“Buy this product now.”)
end
local createGroup = function()
img.tag = {}
img.prod = {}
txt.units = {}
txt.price = {}
btn.buy = {}
for i=1,5 do
prod[i] = display.newGroup()
img.tag[i]= display.newImageRect( prod[i], “PNG/pricetag144x32.png”, 144, 32 )
img.tag[i].x = 45
img.prod[i] = display.newSprite( prod[i], img.prodSheet, img.prodSheetData )
img.prod[i]:setFrame( math.random(1,25) ); img.prod[i].x = -45
txt.units[i] = display.newText( prod[i], “x” … tostring(math.random(1,10000)), 0, 0, native.systemFontBold, 10 );
txt.units[i].anchorX = 0
txt.units[i].x = img.prod[i].x+25; txt.units[i].y = img.prod[i].y+5; txt.units[i]:setFillColor(0.5, 0.5, 0.5)
txt.price[i] = display.newText( prod[i], “$” … tostring(math.random(100,900)), 0, 0, native.systemFontBold, 15 )
txt.price[i].x = img.tag[i].x+40; txt.price[i]:setFillColor(0.5, 0.5, 0.5)
btn.buy[i] = widget.newButton{
sheet = img.btnBuySheet,
defaultFrame = 1,
overFrame = 2,
width = 50,
height = 24,
onRelease = buyNow
}
btn.buy[i].x = img.tag[i].x+70; btn.buy[i].y = img.tag[i].y-15;
prod[i]:insert(btn.buy[i]);
prod[i].x = 86; prod[i].y = 30;
btn.buy[i].alpha = 0
end
end
local onRowRender = function( event )
local row = event.row
row:insert(prod[row.index])
end
local onRowTouch = function( event )
local phase = event.phase
local rowIndex = event.target.index
if phase == “tap” then
for i=1,5 do
btn.buy[i].alpha = 0
end
btn.buy[rowIndex].alpha = 1
end
end
local background = display.newRect(0,0,display.contentWidth, display.contentHeight)
background.x = display.contentCenterX; background.y = display.contentCenterY
createGroup()
local myTable = widget.newTableView
{
width = 230,
height = 230,
hideBackground = true,
noLines = true,
hideScrollBar = true,
onRowRender = onRowRender,
onRowTouch = onRowTouch
}
myTable.x = 120; myTable.y = 185
for i=1,5 do
myTable:insertRow{
rowHeight = 50
}
end
[/lua]
When I place createGroup() inside onRowRender function, it simply breaks.
If I keep it where it is now (which is right above the line where I create myTable), the table comes out just like I want it to – except it ends up with the runtime error I described above.
Thanks again for all your help.
Naomi