使用带有Widget的Corona SDK使用display.newRetinaText显示表数据时出现问题

时间:2014-05-15 18:51:52

标签: lua corona

我正在关注J.A.的视频。在他的教程中,怀特,在我看来是一个梦幻般的Corona SDK商业应用教程。我在屏幕上输入代码时输入了代码。我在添加代码时遇到了一些问题,但是当我显示网格时,我无法将数据填充到屏幕上。我还为我的手机创建了一个版本,并在以前的sdk build 2013.12.7上运行它。这是代码。您可以注释掉ping的引用。

local widget = require("widget")

local top = display.statusBarHeight
local listRecs ={}
local list = nil

local nameData = {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Harris"}


local function setup()
    local bg = display.newRect(0,top, display.contentWidth, display.contentHeight - top)
    bg:setFillColor(0,155,73)
    list = widget.newTableView {top = top +10, height = 450 }
    maskFile = "mask.png"

end

local function loadData()
    for x =1 , #nameData do
        listRecs[x] = {}
        listRecs[x].name = nameData[x]
        listRecs[x].age = math.random(18,35)
        listRecs[x].showDel = false
        print(listRecs[x].name.." "..listRecs[x].age)
    end
end

local function showRecords()

    local function onRowRender(event)
        local row = event.row
        local rowGroup = event.view
        local idx = row.index or 0
        local color = 0

        print("the index value is: "..idx)


        row.textObj = display.newRetinaText(listRecs[idx].name, 0, 0, "Helvetica", 16)
        row.textObj:setTextColor( color )
        row.textObj:setReferencePoint(display.CenterLeftReferencePoint)
        row.textObj.x = 20
        row.textObj.y = rowGroup.contentHeight*0.35

        row.textObj2 = display.newRetinaText(listRecs[idx].age, 0, 0, "Helvetica", 16)
        row.textObj2:setTextColor( color )
        row.textObj2:setReferencePoint(display.CenterLeftReferencePoint)
        row.textObj2.x = 20
        row.textObj2.y = rowGroup.contentHeight*0.65    

        rowGroup:insert(row.textObj)
        rowGroup:insert(row.textObj2)   

    end -- onRowRender

    local function rowListener(event)

    end -- row Listener

    for x = 1, #listRecs do
            list:insertRow{
            onRender = onRowRender,
            listner = rowListener
        }
    end

end -- showRecords

setup()

loadData()

showRecords()

1 个答案:

答案 0 :(得分:0)

这些代码对于当前版本来说太旧了。 请尝试使用当前版本,希望它有所帮助:

local widget = require("widget")

local top = display.statusBarHeight
local listRecs ={}
local list = nil

local nameData = {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Harris"}


local function setup()
    local bg = display.newRect(0,top, display.contentWidth, display.contentHeight - top)
    bg:setFillColor(0,155,73)
    list = widget.newTableView {top = top +10, height = 450 ,onRowRender = onRowRender,     onRowTouch = onRowTouch,}
    maskFile = "mask.png"

end

local function loadData()
    for x =1 , #nameData do
        listRecs[x] = {}
        listRecs[x].name = nameData[x]
        listRecs[x].age = math.random(18,35)
        listRecs[x].showDel = false
        print(listRecs[x].name.." "..listRecs[x].age)
    end
end
function onRowRender(event)
    local row = event.row
    local groupContentHeight = row.contentHeight
    local idx = row.index or 0

    print("the index value is: "..idx)

    local textObj = display.newText( row, listRecs[idx].name, 0, 0, native.systemFontBold, 16 )
    textObj.x = 20
    textObj.anchorX = 0
    textObj.y = groupContentHeight * 0.35
    textObj:setFillColor( 0, 0, 0 )  
    local textObj2 = display.newText( row, listRecs[idx].age, 0, 0, native.systemFontBold, 16 )
    textObj2.x = 20
    textObj2.anchorX = 0
    textObj2.y = groupContentHeight * 0.65
    textObj2:setFillColor( 0, 0, 0 )  
end 
-- onRowRender
local function showRecords()




local function rowListener(event)

end -- row Listener

for x = 1, #listRecs do

        list:insertRow{
    }
end

end -- showRecords

setup()

loadData()

showRecords()