【问题标题】:issue with list TableView in CoronaCorona中的列表TableView问题
【发布时间】:2015-09-25 09:38:05
【问题描述】:

我正在尝试在 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()

【问题讨论】:

    标签: lua coronasdk corona-storyboard


    【解决方案1】:

    你可以修改你的代码如下:

    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 )
    

    我猜应该可以的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多