2014-05-15 55 views
0

我正在關注J.A.的視頻。 Whyte在他的教程中,在我看來,是一款夢幻般的Corona SDK商業應用教程。我在屏幕上輸入代碼時輸入了代碼。我添加了一些故障排除代碼,但在顯示網格時,我無法獲取數據以填充屏幕。我還爲我的手機創建了一個構建,並在之前的sdk build 2013.12.7上運行它。這是代碼。你可以註釋掉對ping的引用。使用display.newRetinaText與Widget顯示錶格數據時出現問題

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() 

回答

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() 
相關問題