Lua Corona中列表TableView的问题
我正在尝试在Corona中制作一个应用程序,该应用程序将在表视图中显示主题/项目列表,但我已经使用它超过2周了,我无法在应用程序上显示列表,但它显示列表上的最后一个项目,而不是在表视图中列出所有项目 我尝试用“listRec[event.index].name”代替“listRec.name”,但出现错误,请帮助我 请参阅下面的代码Lua Corona中列表TableView的问题,lua,coronasdk,corona-storyboard,Lua,Coronasdk,Corona Storyboard,我正在尝试在Corona中制作一个应用程序,该应用程序将在表视图中显示主题/项目列表,但我已经使用它超过2周了,我无法在应用程序上显示列表,但它显示列表上的最后一个项目,而不是在表视图中列出所有项目 我尝试用“listRec[event.index].name”代替“listRec.name”,但出现错误,请帮助我 请参阅下面的代码 local widget = require( "widget" ) listRec = {} local nameData =
local widget = require( "widget" )
listRec = {}
local nameData = {"System1","System2","System3","System4","System5","System6"
,"System7","System8","System9"}
local list = nil
local function loadData()
for x=1, #nameData do
listRec[x] = {}
listRec.name = nameData[x]
end
end
local function onRowRender( event )
-- Get reference to the row group
local row = event.row
local rowGroup = event.view
-- Cache the row "contentWidth" and "contentHeight" because the row bounds can change as children objects are added
local rowHeight = row.contentHeight
local rowWidth = row.contentWidth
local rowTitle = display.newText(row, listRec.name, 0, 0, nil, 35 )
rowTitle:setFillColor( 0 )
-- Align the label left and vertically centered
rowTitle.anchorX = 0
rowTitle.x = 10
rowTitle.y = rowHeight * 0.5
end --onRowRender
local function pageup()
-- Create the widget
tableView = widget.newTableView
{
top = 50,
height = screenHeightSB,
width = screenWidth,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
listener = scrollListener
}
--Heading Outline
local heading = display.newText("Course Outline", 0,0, "Helvetica" or "native.systemFont", 40)
heading.x = centerX
heading.y = 25
end ---pageup
local function showRec()
-- Insert 40 rows
for i = 1, #listRec do
local rowHeight = 60
-- Insert a row into the tableView
tableView:insertRow{
rowHeight = rowHeight
}
end
end --- showRec
loadData()
pageup()
showRec()
您可以按以下方式修改代码:
local function loadData()
for x=1, #nameData do
listRec[x] = {
name = nameData[x]
}
end
end
然后在rowRender函数中添加
local idx = row.index
local rowTitle = display.newText(row, listRec[idx].name, 0, 0, nil, 35 )
我想应该是这样