這是我的代碼和工作的罰款,到目前爲止傳遞SQL行ID來實現代碼如下電暈
local count = 0
for row in db:nrows("select unit.id, builtin_list.* from unit inner join builtin_list on unit.id = builtin_list.unit_id group by artist order by artist asc") do
count = count+1
song[count]={}
song[count].artist = row.artist
end
-- all done with db. close it
db:close()
local function tableViewListener (event)
print(event.phase)
end
local function onRowRender(event)
local row = event.row
local rowTitle = display.newText(row, song[row.index].artist, 10,0, nil, 14)
rowTitle:setTextColor(0,0,0)
end
local function onRowTouch(event)
end
-- tableview
local tableView = widget.newTableView {
left = 0, top = 0,
onRowRender = onRowRender, onRowTouch = onRowTouch, listener = scrollListener
}
for i = 1, count do
local rowHeight = 40
local rowColor = {
default = {255,255,255}
}
local lineColor = { 220,220,220}
tableView:insertRow {
rowHeight = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
rowid = song[count].id
}
end
這是工作的罰款。它顯示來自sql的結果數據。我想通過將來自同一個sql表的其他獨特屬性傳遞給每一行來實現ontouch函數,這樣當單擊該行時,它就會將該數據專門用於該單擊的行。我曾嘗試將自定義變量添加到rowTitle(rowTitle.someData ='test'),但這似乎並未傳遞到onRowTouch事件。