如何在corona sdk中识别在表格中触摸的对象?

假设在corona中我有一个带有三个不同id的对象的单元格的表格视图,我可以识别行的触摸,但是如何识别在表格视图内触摸的对象呢?

enter image description here

这是我使用的代码

local function onRowRender( event )
  local row = event.row
  local rowHeight = row.contentHeight
  local rowWidth = row.contentWidth

  local speaker1 = display.newImage(row,"images/listen.png",70,70)
  speaker1.width = 20;speaker1.height = 20*ryx
  speaker1.x = 35;speaker1.y = suby
  speaker1.id = "speaker1"

  local eye1 = display.newImage(row,"images/eye.png",70,70)
  eye1.width = 20;eye1.height = 20*ryx
  eye1.x = 60;eye1.y = suby
  eye1.id = "eye1"

  speaker1:addEventListener("touch",onObjectTouch)
  eye1:addEventListener("touch",onObjectTouch)

end

local function onRowTouch( event )
    local phase = event.phase
    local row = event.target

    touchedRowIndex = row.index

    print(event.target.id)
    print(event.target)
    print(event.target.name)

  if ( "release" == phase ) then
    return true
  end
end

我尝试为每个对象使用触摸侦听器,但没有成功

点赞
用户2858170
用户2858170
在这里,你添加了 `onObjectTouch` 的EventListener,但是你实现的是 `onRowTouch`。

你应该实现 `onObjectTouch` 或者重命名已添加的EventListener。
speaker1:addEventListener("touch",onObjectTouch)
eye1:addEventListener("touch",onObjectTouch)
2016-04-29 12:30:31