I’m building a poetry app and I’ve used a Tableview to index all of the available poems, but when you scroll it all of the row titles change and become the same. I’ve attached before and after photos to give a better idea of what I’m saying.
Here is the code that I am calling:
local poems = require("poems") local function onRowRender( event ) local row = event.row local rowHeight = row.contentHeight local rowWidth = row.contentWidth local rowTitle = display.newText( { parent = row, text = poems[poemNum].title, 0,0,nil,fontSize = sizeSetting} ) rowTitle:setFillColor( 0.25,0.25,0.25 ) rowTitle.x = W/2 rowTitle.y = rowHeight/2 end local function onRowTouch( event ) if (event.phase=="tap") then poemNum = event.target.index poemList.isVisible = false poemMain = display.newText( { font = native.systemFont, width = W, fontSize = sizeSetting, x = W/2, y = H/2, text = poems[poemNum].text, align = "center"} ) poemMain.anchorY = -1 poemMain.y = 30 poemMain:setTextColor( 0.3, 0.3, 0.3 ) poemScroll:insert( poemMain ) poemScroll:scrollToPosition( {y=0, time=0} ) poemScroll.isVisible = true poemMain.isVisible = true homeButton.isVisible = false MSbackButton.isVisible = true MSdonateButton.isVisible = true end end function poemButton:tap () bg\_sprite:setSequence( "main" ) bg\_sprite:play( ) ads.show( "banner", {x =0, y=H-90} ) OS\_group.isVisible = false poemList.isVisible = true homeButton.isVisible = true for i=1,#poems do poemNum = i poemList:insertRow{rowHeight=88, rowColor = {}} end end poemList = widget.newTableView ({ top = 98, left = 0, width = W-10, height = H - 196, onRowRender = onRowRender, onRowTouch = onRowTouch, listener = scrollListener }) poemList.isVisible = false