2016-11-27 65 views
0

everyone: 我可以访问到TableView中的行内容:这是我的问题,我试图在单击时显示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的

我会感谢所有帮助,谢谢

回答

1

我想你应该将数据存储在单独的变量中,并将其传递给参数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,你可以做这样的事情你Corona blog找到

local function onRowTouchTable(event) 
    local row = event.target 
    local id = row.index -- or row.id I'm not sure 

    print(myData[id]) 
end 

更多信息。此外,你可以看到YouTube视频Corona University - Displaying Database Data Using TableView Widgets

+0

好的我明白了,但存在另一种解决方案?想知道。 –

+0

我不知道另一个解决方案。 – ldurniat