tableView and TakeFocus

I am using a tableView where some rows have 3 buttons (touch listeners). I usually use scrollviews but the delayed rendering of rows in a tableView was the main reason I chose to use a tableView instead.

But it seems that the takeFocus function call does not exist, which I think is required to make a distinction between scrolling and pressing a button

How can I pass the touch event back to the tableView when a touch event on my button is a scroll movement? See code below.

function scene:onImageTouch(evt) if evt.phase == "began" then print ("imagetouch began") -- animate a button down elseif evt.phase == "moved" then local dy = math.abs((evt.y - evt.yStart)) if dy\>10 then print ("imagetouch moved") -- raises error: takeFocus is nil myTableView:takeFocus(evt) end elseif evt.phase == "ended" then print ("imagetouch ended") -- animate a button up self:onButtonPressed() end return true end

I have worked around the issue by moving the tableView myself. In the “moved” state of the touch event, I call the tableView’s  scrollToY function to move it to the desired position. It is not an ideal solution, but it works. Hopefully the takeFocus call will be added soon.

Here’s part of the touch handler:

if evt.phase == "began" then scrolled = false print ("imagetouch began") -- save the initial y-position of the tableView tableViewYStart = self.myTableView:getContentPosition() -- omitted the "button down" animation elseif evt.phase == "moved" then local dy = ((evt.y - evt.yStart)) if dy \> 10 or dy \< -10 then scrolled = true self.myTableView:scrollToY({y=(tableViewYStart+dy), time=0}) -- omitted the "button up" animation end elseif evt.phase == "ended" then if scrolled == false then -- omitted the "onbuttonpress" logic

end

print (“imagetouch ended”)

– omitted the “button up” animation

end

return true

I’m glad you found a solution. widget.newTableView() does not have a takeFocus() method. ScrollView’s do.

Rob

Hi Rob, thanks for responding. I got it working so all is good.

Do you think that there’s a chance this method will be implemented? It really makes sense to have it there. The way I solved it just killed the good tableView stuff like automatic back-bouncing when I scroll past beginning or end (scrollToY doesn’t bounce).

Regards,

~SpringMorning

I would suggest going to the feedback site (https://feedback.coronalabs.com) and putting a request for this and getting it voted up.

You could also grab the open source code for the widget library (all Lua) and look at the code for scrollView’s takeFocus() and see if you can implement it for yourself for the tableView.

Rob

I have worked around the issue by moving the tableView myself. In the “moved” state of the touch event, I call the tableView’s  scrollToY function to move it to the desired position. It is not an ideal solution, but it works. Hopefully the takeFocus call will be added soon.

Here’s part of the touch handler:

if evt.phase == "began" then scrolled = false print ("imagetouch began") -- save the initial y-position of the tableView tableViewYStart = self.myTableView:getContentPosition() -- omitted the "button down" animation elseif evt.phase == "moved" then local dy = ((evt.y - evt.yStart)) if dy \> 10 or dy \< -10 then scrolled = true self.myTableView:scrollToY({y=(tableViewYStart+dy), time=0}) -- omitted the "button up" animation end elseif evt.phase == "ended" then if scrolled == false then -- omitted the "onbuttonpress" logic

end

print (“imagetouch ended”)

– omitted the “button up” animation

end

return true

I’m glad you found a solution. widget.newTableView() does not have a takeFocus() method. ScrollView’s do.

Rob

Hi Rob, thanks for responding. I got it working so all is good.

Do you think that there’s a chance this method will be implemented? It really makes sense to have it there. The way I solved it just killed the good tableView stuff like automatic back-bouncing when I scroll past beginning or end (scrollToY doesn’t bounce).

Regards,

~SpringMorning

I would suggest going to the feedback site (https://feedback.coronalabs.com) and putting a request for this and getting it voted up.

You could also grab the open source code for the widget library (all Lua) and look at the code for scrollView’s takeFocus() and see if you can implement it for yourself for the tableView.

Rob