如何通过单击行来访问 TableView 中的行内容
How can I access, to the row content in a TableView, by clicking the row
大家:
这是我的问题,我试图在单击时显示 TableView 中选定行的内容。
在 onRowRender 中,我通过这种方式添加行,
local function onRowRender( event )
local row = event.row
local myText = ""
local myText = display.newText(row,"Text to show",150,row.contentHeight/2,native.systemFontBold,30 )
end
在 onRowTouch 事件中我试过了,
local function onRowTouchTable( event )
print(menuPedidos._view._rows[row.index]) //it return a table, I assumed the row selected
print(menuPedidos._view._rows[row.index].mytext) //it return nil
end
而我需要的是对象中保存的文本 mytext
如有任何帮助,我将不胜感激,谢谢
我认为您应该将数据存储在单独的变量中,将其传递到 insertRow
中的参数中,并在 insertRow
中也设置行的 ID 以便稍后引用它们。
示例
for i = 1, #myData do
myList:insertRow{
rowHeight = 60,
id = i,
isCategory = false,
rowColor = { 1, 1, 1 },
lineColor = { 0.90, 0.90, 0.90 },
params = {
name = myData[i].name,
phone = myData[i].phone
}
}
end
所以在 onRowTouchTable
你可以做类似的事情
local function onRowTouchTable(event)
local row = event.target
local id = row.index -- or row.id I'm not sure
print(myData[id])
end
您可以在 Corona blog. Also, you can see youtube video Corona University - Displaying Database Data Using TableView Widgets 上找到更多信息。
大家: 这是我的问题,我试图在单击时显示 TableView 中选定行的内容。
在 onRowRender 中,我通过这种方式添加行,
local function onRowRender( event )
local row = event.row
local myText = ""
local myText = display.newText(row,"Text to show",150,row.contentHeight/2,native.systemFontBold,30 )
end
在 onRowTouch 事件中我试过了,
local function onRowTouchTable( event )
print(menuPedidos._view._rows[row.index]) //it return a table, I assumed the row selected
print(menuPedidos._view._rows[row.index].mytext) //it return nil
end
而我需要的是对象中保存的文本 mytext
如有任何帮助,我将不胜感激,谢谢
我认为您应该将数据存储在单独的变量中,将其传递到 insertRow
中的参数中,并在 insertRow
中也设置行的 ID 以便稍后引用它们。
示例
for i = 1, #myData do
myList:insertRow{
rowHeight = 60,
id = i,
isCategory = false,
rowColor = { 1, 1, 1 },
lineColor = { 0.90, 0.90, 0.90 },
params = {
name = myData[i].name,
phone = myData[i].phone
}
}
end
所以在 onRowTouchTable
你可以做类似的事情
local function onRowTouchTable(event)
local row = event.target
local id = row.index -- or row.id I'm not sure
print(myData[id])
end
您可以在 Corona blog. Also, you can see youtube video Corona University - Displaying Database Data Using TableView Widgets 上找到更多信息。