Corona 中列表 TableView 的问题
issue with list TableView in Corona
我正在尝试在 Corona 中做一个应用程序,它将在 table 视图中显示 topics/items 的列表,但我已经使用它超过 2 周了,我无法在应用程序,但它显示列表中的最后一项,而不是在 tableView
中列出所有项
我已经尝试用 "listRec[event.index].name" 代替 "listRec.name" 但出现错误,请帮助我
请参阅下面的代码
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 )
我想应该可以了
我正在尝试在 Corona 中做一个应用程序,它将在 table 视图中显示 topics/items 的列表,但我已经使用它超过 2 周了,我无法在应用程序,但它显示列表中的最后一项,而不是在 tableView
中列出所有项我已经尝试用 "listRec[event.index].name" 代替 "listRec.name" 但出现错误,请帮助我 请参阅下面的代码
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 )
我想应该可以了