在Corona中列出TableView的问题

时间:2015-07-07 18:17:35

标签: lua corona corona-storyboard

我试图在Corona中创建一个应用程序,它会在表格视图中显示主题/项目列表,但我已经使用它超过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()

1 个答案:

答案 0 :(得分:0)

您可以按以下方式修改代码:

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 )

应该这样做我猜