【问题标题】:How can I access, to the row content in a TableView, by clicking the row如何通过单击行来访问 TableView 中的行内容
【发布时间】:2017-04-11 08:20:21
【问题描述】:

大家: 这是我的问题,当我单击时,我试图在 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

中的文本

如果有任何帮助,我将不胜感激,谢谢

【问题讨论】:

    标签: android lua widget tableview coronasdk


    【解决方案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 你可以做类似的事情

    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 上找到更多信息。另外,你可以看youtube视频Corona University - Displaying Database Data Using TableView Widgets

    【讨论】:

    • 我不知道其他解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2021-12-21
    • 2022-11-25
    相关资源
    最近更新 更多