cannot show data in rows (tableView problem)

Hi,

I can’t show data in rows, I’m using the latest public build

here’s my code :

local centerX = display.contentCenterX local centerY = display.contentCenterY local top = display.statusBarHeight local widget = require("widget") local listRecs = {} local nameData = {"Mohammed","Ali","Fatimah","Hassan","Hussain"} local ages = { 63,63,18,47,57} local list = nil local function setup() local bg = display.newRect(centerX,centerY, display.contentWidth, display.contentHeight) bg:setFillColor(0.367,0,2.755) list = widget.newTableView { top = top + 10, left = 10, width = 300, height = 320 } end local function loadData() for i=1,#nameData do listRecs[i] = {} listRecs[i].name = nameData[i] listRecs[i].age = ages[i] listRecs[i].showDel = false print(listRecs[i].name .. " A.S ,age " .. listRecs[i].age) end end local function showRecords() local function onRowRender( event ) local row = event.row local rowGroup = event.view local idx = event.index or 0 local color = 0 row.textObj = display.newText(listRecs[idx].name,0,0,"Helvetica", 18) row.textObj:setFillColor(color) row.textObj.anchorX = 0 row.textObj.x = 20 row.textObj.y = rowGroup.contentHeight \* 0.35 rowGroup:insert(row.textObj) end local function rowListener( event ) -- body end for i=1,#listRecs do list:insertRow { onRender = onRowRender, listener = rowListener } end end setup() loadData() showRecords()

is there something wrong I did  :mellow:

Actually, there is quite a bit incorrect here. When you create the tableView, you have to tell it the function that will handle row generation and handle other tableView events.  You’ve also have scope issues where somethings cant see things.  Our examples for tableView should not be abstracted and re-arranged. It’s best if you just follow the design pattern we have it.  Your code should be structured:

local function onRowTouch( event )     -- handle any events touching the row. end local function onRowRender( event )     -- code to draw each row end local function scrollListener( event )    -- code to manage anything you need to do when the tableview scrolls end local tableView = widget.newTableView({     top = top + 10,     left = 10,     width = 300,     height = 320,     onRowRender = onRowRender,     onRowTouch = onRowTouch,     listener = scrollListener })

Once you have this setup, in this order and not inside another function, then you can run your loop to insert the records.

Rob

Thank You Rob, after I did what you said, I got everything working.

Actually, there is quite a bit incorrect here. When you create the tableView, you have to tell it the function that will handle row generation and handle other tableView events.  You’ve also have scope issues where somethings cant see things.  Our examples for tableView should not be abstracted and re-arranged. It’s best if you just follow the design pattern we have it.  Your code should be structured:

local function onRowTouch( event )     -- handle any events touching the row. end local function onRowRender( event )     -- code to draw each row end local function scrollListener( event )    -- code to manage anything you need to do when the tableview scrolls end local tableView = widget.newTableView({     top = top + 10,     left = 10,     width = 300,     height = 320,     onRowRender = onRowRender,     onRowTouch = onRowTouch,     listener = scrollListener })

Once you have this setup, in this order and not inside another function, then you can run your loop to insert the records.

Rob

Thank You Rob, after I did what you said, I got everything working.