setFocus on TableView

Good day I was wondering on how can I set the focus on my TableView? it works with the scrollView but apparantly it doesn’t work to TableView

here is my code:

handleButtonEvent = function(event) local self = event.target local phase = event.phase if phase == "began" then display.getCurrentStage():setFocus( event.target ) if self.id == "back" then if self.state == "up" then self.state = "down" self.front.isVisible = false self.back.isVisible = true else end end elseif phase == "moved" then local dy = math.abs( ( event.y - event.yStart ) ) local dx = math.abs( ( event.x - event.xStart ) ) -- print(dy) print(dy) if ( dy \> 10 ) then uiInterface.tableView:setFocus( event ) return false end

thanks in advance

Hi @vonncc123,

I would caution you against trying to set focus here. Tableviews are made up of many different moving parts: the Tableview itself, rows within the Tableview, and even interactive items (i.e. buttons) that you may have inserted into the rows. Setting focus on one of the elements could completely disable functionality of the others, unless you’re exceedingly careful about releasing that focus at the proper touch phases across all potential events.

Can you describe in more detail why you’re wanting to set focus on this object?

Best regards,

Brent

I have a button inside a Row, and an Image with a touch event, If I want to scroll Up and Down, it doesn’t go through the button.

Hi @vonncc123,

I would caution you against trying to set focus here. Tableviews are made up of many different moving parts: the Tableview itself, rows within the Tableview, and even interactive items (i.e. buttons) that you may have inserted into the rows. Setting focus on one of the elements could completely disable functionality of the others, unless you’re exceedingly careful about releasing that focus at the proper touch phases across all potential events.

Can you describe in more detail why you’re wanting to set focus on this object?

Best regards,

Brent

I have a button inside a Row, and an Image with a touch event, If I want to scroll Up and Down, it doesn’t go through the button.