Борясь с проблемой! Мне нужно вставить в tableview результат запроса БД. Проблема в том, что я не могу вставлять данные, поскольку, когда я делаю это, результат равен нулю ... Если я попытаюсь вставить фиксированные данные (например, общую строку «привет»), это сработает! Кто-нибудь может мне помочь? Большое спасибо.corona sdk insert row tableview
function listatornei()
local dataURL = "http://www.lineitup.it/torneiopen.php?me="..usrUsr
numtornei=0
local function listaListener(event)
if event.phase=="ended" then
if (event.isError) then
print("Connection not available")
else
id_tor = {} -- array to store query field1
usr_tor = {} -- array to store query field2
local tab = event.response -- read json data
tab = json.decode(tab) -- tabel conversion
if #tab > 0 then
for i=1, #tab do
id_tor[i] = tab[i]["idt"]
usr_tor[i] = tab[i]["gioc1_usr"]
numtornei=i
end
-- Listen for tableView events
local function tableViewListener(event)
local phase = event.phase
print(event.phase)
end
-- Handle row rendering
local function onRowRender(event)
local phase = event.phase
local row = event.row
local id = row.index
row.bg = display.newRect(0, 0, display.contentWidth, 60)
row.bg.anchorX = 0
row.bg.anchorY = 0
row.bg:setFillColor(1, 1, 0)
row:insert(row.bg)
row.idt = display.newText(id_tor[i], 0, 0, native.systemFontBold, 40)
--row.idt = display.newText("pippo", 0, 0, native.systemFontBold, 40)
row.idt.anchorX = 0
row.idt.anchorY = 0.5
row.idt:setFillColor(0)
row.idt.y = 20
row.idt.x = 42
row.usr = display.newText(usr_tor[i], 0, 0, native.systemFont, 40)
--row.usr = display.newText("pluto", 0, 0, native.systemFont, 40)
row.usr.anchorX = 0
row.usr.anchorY = 0.5
row.usr:setFillColor(0.5)
row.usr.y = 20
row.usr.x = 250
row:insert(row.idt)
row:insert( row.usr)
end
-- Handle row's becoming visible on screen
local function onRowUpdate(event)
local row = event.row
print("Row:", row.index, " is now visible")
end
-- Handle touches on the row
local function onRowTouch(event)
local phase = event.phase
if "press" == phase then
print("Touched row:", event.target.index)
end
end
-- Create a tableView
local tableView = widget.newTableView
{
top = 100,
width = 620,
height = 410,
--maskFile = "formlog1.png",
listener = tableViewListener,
onRowRender = onRowRender,
onRowTouch = onRowTouch,
}
for i = 1, numtornei do
local isCategory = false
local rowHeight = 60
local rowColor =
{
default = { 255, 255, 0 },
}
local lineColor = { 220, 220, 220 }
-- Make some rows categories
if i == 25 or i == 50 then
isCategory = true
rowHeight = 24
rowColor =
{
default = { 150, 160, 180, 200 },
}
end
-- Insert the row into the tableView
tableView:insertRow
{
isCategory = isCategory,
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
}
end
end
end
end
end
network.request(dataURL, "GET", listaListener)
end
Привет, Роб, спасибо! Хотя я не проверял, является ли результат запроса нулевым, я знаю, что в конкретном тестовом случае это не так, поэтому я все еще задаюсь вопросом, что не так в моем коде, чтобы получить список. Проблема в том, что в функции onRowRender переменные id_tor и id_usr не распознаются, тогда как в цикле «for» я проверил их. Любая дополнительная помощь? – ubaldo